728x90
반응형
문제 : 해커랭크 - Strong Password
난이도 : easy
언어 : C++
https://www.hackerrank.com/challenges/strong-password/problem
// Complete the minimumNumber function below.
int minimumNumber(int n, string password) {
// Return the minimum number of characters to make the password strong
string numbers = "0123456789";
string lower_case = "abcdefghijklmnopqrstuvwxyz";
string upper_case = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string special_characters = "!@#$%^&*()-+";
int passwordLength = password.length();
int countLower = 0;
int countUpper = 0;
int countSpecialChar = 0;
int countNumber = 0;
int addreq = 0;
for (int i = 0; i < passwordLength; i++)
{
if (numbers.find(password.at(i)) != -1)
{
countNumber++;
continue;
}
if (lower_case.find(password.at(i)) != -1)
{
countLower++;
continue;
}
if (upper_case.find(password.at(i)) != -1)
{
countUpper++;
continue;
}
if (special_characters.find(password.at(i)) != -1)
{
countSpecialChar++;
continue;
}
}
if (countNumber == 0)
{
addreq++;
}
if (countLower == 0)
{
addreq++;
}
if (countUpper == 0)
{
addreq++;
}
if (countSpecialChar == 0)
{
addreq++;
}
if (6- passwordLength > addreq)
{
return 6- passwordLength;
}
return addreq;
}
728x90
반응형
'개발 > 코딩' 카테고리의 다른 글
해커랭크(HackerRank) - Running Time of Algorithms / C++ (0) | 2020.07.11 |
---|---|
재귀(Recusion) 알고리즘 사용 예 (1) | 2020.07.10 |
해커랭크(HackerRank) - CamelCase / C++ (0) | 2020.06.30 |
해커랭크(HackerRank) - Drawing Book / C++ (0) | 2020.06.30 |
해커랭크(HackerRank) - Climbing the Leaderboard / C++ (0) | 2020.06.29 |
댓글