2018년 3월 30일 금요일

[C++] HackerRank Strong Password

/*
https://www.hackerrank.com/challenges/strong-password/problem

You should use string functions like islower(),isupper(),isdigit() to solve.

There is an easy mistake to make when password shorter than 6. Sometimes the password will need to be longer than 6 to satisfy all criteria.

*/


#include <bits/stdc++.h>

using namespace std;

int minimumNumber(int n, string password) {
    int len = password.length();
    int num_low = 0, num_upp = 0, num_dig = 0, num_spe = 0;
    int count = 0;
   
    for(int i=0;i<len;i++) {
        if(islower(password[i])) {
            num_low++;
        } else if(isupper(password[i])) {
            num_upp++;
        } else if(isdigit(password[i])) {
            num_dig++;
        } else {
            num_spe++;
        }
    }
   
    if(num_low == 0) count++;
    if(num_upp == 0) count++;   
    if(num_dig == 0) count++;
    if(num_spe == 0) count++;
   
    return max(6-len,count);
}

int main() {
    int n;
    cin >> n;
    string password;
    cin >> password;
    int answer = minimumNumber(n, password);
    cout << answer << endl;
    return 0;
}

댓글 없음:

댓글 쓰기