+ 4

I'm not able to pass the 4th test case(hidden) please help me out with my code in c.

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: Strong Here is my code--->> https://code.sololearn.com/ci4ZCvOz7tXh/?ref=app

28th Jun 2020, 7:36 AM
Ayushi Singhaniya
Ayushi Singhaniya - avatar
4 Answers
+ 22
#include<stdio.h> #include<string.h> int main(){ int i, n=0, m=0; char s[30]; scanf("%s",s); if(strlen(s) >= 7){ for(i=0; s[i]!='\0'; i++){ if(s[i]=='#'||s[i]=='
#x27;||s[i]=='%'||s[i]=='&'||s[i]=='*'||s[i]=='!'||s[i]=='@') ++n; if(s[i]=='0'||s[i]=='1'||s[i]=='2'||s[i]=='3'||s[i]=='4'||s[i]=='5'||s[i]=='6'||s[i]=='7'||s[i]=='8'||s[i]=='9') ++m; } } if(n>=2 && m>=2) printf("Strong"); else printf("Weak"); return 0; }
28th Jun 2020, 7:42 AM
➙₄₳Ⱡ₳₭➙
➙₄₳Ⱡ₳₭➙ - avatar
+ 2
//You can use this method to solve this problem #include <stdio.h> #include <string.h> int main() { char pass[100]; scanf("%s", &pass); char ch[8] = {'!', '@', '#', '
#x27;, '%', '&', '*'}; char num[10] = {'1', '2', '3','4', '5', '6','7', '8', '9', '0'}; int i, j, cc = 0, nc = 0, k, l; l = strlen(pass); //printf("%d", l); while(pass[i] != '\0') { for(j = 0; j <= 10; j++) { if(num[j] == pass[i]) { nc++; } } for(k = 0; k<= 7; k++) { if(ch[k] == pass[i]) { cc++; } } i++; } if(cc > 1 && nc > 1 && l > 6){ printf("Strong"); } else { printf("Weak"); } return 0; }
15th Oct 2021, 11:34 AM
GURURAJ KL
GURURAJ KL - avatar
+ 1
Thank you so much, Zoya
28th Jun 2020, 8:05 AM
Ayushi Singhaniya
Ayushi Singhaniya - avatar
+ 1
Its my solution for c# ################ using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Sololearn { class Program { static void Main(string[] args) { string pass=Console.ReadLine(); int number=0,number1=0; Char[] horofKhas={'!','@','#','
#x27;,'%','&','*'}; if (pass.Length>=7) { Char [] harf = pass.ToCharArray(); foreach (Char a in harf) { if(Char.IsNumber(a)) { number++; } else { foreach (char b in horofKhas) { if(a==b) { number1++; } } } } if(number>=2 && number1>=2) { Console.WriteLine ("Strong"); } else { Console.WriteLine("Weak"); } } else { Console.WriteLine("Weak"); } } } }
19th Aug 2021, 8:30 AM
Namdar Vali
Namdar Vali - avatar