※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※

 

이번에 볼 문제는 백준 15239번 문제인 Password check이다.
문제는 아래 링크를 확인하자.

https://www.acmicpc.net/problem/15239 

 

15239번: Password check

Dublin City University wants to prevent students and staff from using weak passwords. The Security Department has commissioned you to write a program that checks that some passwords meet all the quality requirements defined by the Password Guidelines Counc

www.acmicpc.net

각 문자열이 문제에서 요구하는 다섯가지 조건을 만족하는지를 판단하는 문제이다.

 

테스트케이스의 수가 충분히 적고 문자열의 길이가 충분히 짧으므로 각 문자가 각 조건을 만족하는 문자인지를 일일 확인하는 것으로 문제를 해결할 수 있다.

 

아래는 제출한 소스코드이다.

#include <iostream>
#include <string>
using namespace std;

int cnt[128];
string symbols = "+_)(*&^%$#@!./,;{}";

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

	int T; cin >> T;
	while (T--) {
		bool chk1 = 0, chk2 = 0, chk3 = 0, chk4 = 0, chk5 = 0;
		int slen; string s; cin >> slen >> s;
		for (auto l : s) {
			if ('a' <= l && l <= 'z') chk1 = 1;
			if ('A' <= l && l <= 'Z') chk2 = 1;
			if ('0' <= l && l <= '9') chk3 = 1;
			for (auto sym : symbols) {
				if (sym == l) chk4 = 1;
			}
		}
		if (slen >= 12) chk5 = 1;

		if (chk1 && chk2 && chk3 && chk4 && chk5) cout << "valid\n";
		else cout << "invalid\n";
	}
}
728x90

'BOJ' 카테고리의 다른 글

[BOJ 13224 // C++] Chop Cup  (0) 2022.11.25
[BOJ 16175 // C++] General Election  (0) 2022.11.24
[BOJ 13240 // C++] Chessboard  (0) 2022.11.24
[BOJ 20017 // C++] Топот котов  (0) 2022.11.24
[BOJ 10104 // C++] Party Invitation  (0) 2022.11.24

+ Recent posts