-
Notifications
You must be signed in to change notification settings - Fork 9
/
strong-password.cpp
87 lines (71 loc) · 1.83 KB
/
strong-password.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// https://www.hackerrank.com/challenges/strong-password/problem
#include <bits/stdc++.h>
using namespace std;
bool has_lower(string pass)
{
for(int i =0; i < pass.size(); i++)
{
if(islower(pass[i]))
return true;
}
return false;
}
bool has_uppercase(string pass)
{
for(int i=0; i < pass.size(); i++)
{
if(isupper(pass[i]))
return true;
}
return false;
}
bool password_has_special_char(string pass)
{
for(int i=0; i < pass.size(); i++)
{
if(pass[i] == '!' || pass[i] == '@' || pass[i] == '#' ||
pass[i] == '$' || pass[i] == '%' || pass[i] == '^' ||
pass[i] == '&' || pass[i] == '*' || pass[i] == '(' || pass[i]== ')' || pass[i] == '-' || pass[i] == '+')
return true;
}
return false;
}
bool password_has_at_least_one_digit(string pass)
{
for(int i =0; i < pass.size(); i++)
{
if(isdigit(pass[i]))
return true;
}
return false;
}
// Complete the minimumNumber function below.
int minimumNumber(int n, string password) {
//if(password.size() < 6)
// return 6 - password.size();
// If password.size() >=0 and all the conditions are spected, return 0;
int solution = 0;
if(!password_has_at_least_one_digit(password))
solution++;
if(!password_has_special_char(password))
solution++;
if(!has_lower(password))
solution++;
if(!has_uppercase(password))
solution++;
int diff = 6 - password.size();
return max(solution, diff);
}
int main()
{
ofstream fout(getenv("OUTPUT_PATH"));
int n;
cin >> n;
cin.ignore(numeric_limits<streamsize>::max(), '\n');
string password;
getline(cin, password);
int answer = minimumNumber(n, password);
fout << answer << "\n";
fout.close();
return 0;
}