0
What is wrong with my code for the following question ? My code is in comment section.It is showing error in 4 and 13 test case.
You're interviewing to join a security team. They want to see you build a password evaluator for your technical interview to validate the input. Task: Write a program that takes in a string as input and evaluates it as a valid password. The password is valid if it has at a minimum 2 numbers, 2 of the following special characters ('!', '@', '#', '
#x27;, '%', '&', '*'), and a length of at least 7 characters. If the password passes the check, output 'Strong', else output 'Weak'. Input Format: A string representing the password to evaluate. Output Format: A string that says 'Strong' if the input meets the requirements, or 'Weak', if not. Sample Input: Hello@$World19 Sample Output: Strong9 RĂ©ponses
+ 2
Mahak Garg
First, you dont need to count uppercase letters and lowercase letters and whitespace. You just need the number of symbols and digits.
Second, You forgot the second else statement outside the for loop. If you have more question, feel free to ask.
https://code.sololearn.com/c8zzCz71SlSA/?ref=app
+ 2
Your first code structure looked like this.
if True
if True
//strong
else
//weak
This should be:
if True
if True
//strong
else
//weak
else
//weak
+ 1
#include <iostream>
#include <string>
using namespace std;
int main()
{
int l = 0, u = 0,d = 0, sy = 0, sp = 0,i;
string s;
cin>>s;
int l1 = s.length();
if(l1>=7)
{
for(i=0;i<l1;i++)
{
if(islower(s[i]))
{
l+=1;
}
else if(isupper(s[i]))
{
u+=1;
}
else if(isdigit(s[i]))
{
d+=1;
}
else if(isspace(s[i]))
{
sp+=1;
}
else if(s[i] == '!' || s[i] == '@' || s[i] == '#' || s[i] == '#x27; || s[i] == '%' || s[i] == '&' || s[i] == '*' || s[i] == '_')
{
sy+=1;
}
}
if(l>=1 && u>=1 && d>=2 && sy>=2 && sp>=0)
{
cout<<"Strong";
}
else
{
cout<<"Weak";
}
}
}
+ 1
I got your point ă Nicko12 ă
Thanks for your help.
+ 1
Hmm. Ok although Im not very familiar with Java. But yeah fine maybe I can help somehow.
+ 1
@ăNicko12ă I have completed my java code so if you want you can leave it. đ
+ 1
Mahak Garg Glad you solved it. I cant figure it out though, not familiar with syntax. đ
+ 1
That's alright đ
0
ă Nicko12 ă Can you please help me out with my java code as well for the same question ?