0
Problem: Password validation
HERE IS MY SOLUTION. I READ IT A MILLION TIMES AND STILL DON’T GET, WHERE THE BUG IS. IT ONLY MISSES 2 CASES. I’LL BE GLAD IF SOMEONE POINTS OUT MY MISTAKE. #include <bits/stdc++.h> using namespace std; string pass; char spec[] = { '!', '@', '#', '
#x27;, '%', '&', '*' }; bool isLongEnough() { return pass.size() >= 7; } bool isWithNumbersAndSpecials() { int count = 0; int spec1 = -1; int spec2 = -1; for(int i = 0; i < pass.size(); i++) { if(pass[i] >= '0' && pass[i] <= '9') { count++; } for(int j = 0; j < 7; j++) { if(pass[i] == spec[j]) { if(spec1 != -1 && pass[i] != pass[spec1]) { spec2 = i; } if(spec1 == -1) { spec1 = i; } break; } } } return count >= 2 && spec2 != -1; } int main() { getline(cin, pass); if(isLongEnough() && isWithNumbersAndSpecials()) { cout <<"Strong" <<endl; } else { cout <<"Weak" <<endl; } return 0; }5 Respuestas
+ 3
Kristiyan Garchev the question specifies that the password is strong if it have any two characters are special characters ( they need not to be distinct)
Your code fails on test case like this :-
12@@abcde
Your output -> Weak
Expected output -> Strong
A simple fix is to remove that condition from your if statement 👇
https://code.sololearn.com/cCMd3trLpq3k/?ref=app
+ 1
Thank you, Arsenic !
0
Is it possible for you to show me your code?
0
Sorry, can you see it now?
- 1
Mention language too.