+ 1

What is the mistake that i have made?

The following program is code coach password validation program in cpp. I think this program was done. But in test cases, case 8 fails. Please review it. https://code.sololearn.com/c8iWg8F3CTyV/?ref=app

2nd Jan 2020, 8:01 AM
Asrar
Asrar - avatar
3 Antworten
+ 3
#include <iostream> using namespace std; void valid(string x) { char c; int i,k=0,symbol = 0,s1; s1=x.size(); for (i=0;i<s1;i++) { c=x[i]; if((c>='0') && c<='9') k+=1; else if((c=='!'||c=='@'|| c=='#'||c=='
#x27;||c=='%'|| c=='&'||c=='*')) symbol+=1; } if(k>=2 && symbol >= 2) cout<<"Strong"; else cout<<"Weak"; } int main() { string a; int s; cin>>a; s=a.size(); if(s>=7) valid(a); else cout<<"Weak"; return 0; }
2nd Jan 2020, 11:34 AM
minirkk
minirkk - avatar
+ 2
in your code you made a mistake in the statement k += 0 also keep in mind to check only those 7 special symbols and not other symbols aprt from them. Another mistake you've commit is that you count both the symbols and digit in one variable k and you are checking if k is greater than 4 now lets take an example where the code fails- Input: asrar7*!# Output: Strong (according to your code) Correct output: Weak(since only 1 digit) Because k will be equal to 4 but according to the challenge atleast 2 digits were needed, so counting them seperately would have solve the problem.🙂
2nd Jan 2020, 11:35 AM
minirkk
minirkk - avatar
0
RKK Thank you
2nd Jan 2020, 1:05 PM
Asrar
Asrar - avatar