안녕하세요. 오늘은 강력한 비밀번호를 만들 거예요.

문제

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

아이디어

일단 기본적으로 6칸은 채워야합니다.
그리고 소문자, 대문자, 숫자, 특수문자 중에서 없는 개수를 찾습니다.
두 값의 최댓값을 출력해주면 됩니다.

소스코드

#include <iostream>
#include <string>
#include <algorithm>
#define ll long long
using namespace std;

int main(void)
{
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	ll len, i, cnt = 4;
	bool small = true, large = true, number = true, other = true;
	string s;

	cin >> len >> s;
	for (i = 0; i < len; i++)
	{
		if ('a' <= s[i] && s[i] <= 'z')
		{
			if (small)
			{
				small = false;
				cnt--;
			}
		}
		else if ('A' <= s[i] && s[i] <= 'Z')
		{
			if (large)
			{
				large = false;
				cnt--;
			}
		}
		else if ('0' <= s[i] && s[i] <= '9')
		{
			if (number)
			{
				number = false;
				cnt--;
			}
		}
		else if (other)
		{
			other = false;
			cnt--;
		}
	}

	cout << max(6 - len, cnt);
}


감사합니다.

0개의 댓글