+ 1
Password Rules help!
I cAnt tHE BUG, TEST CASE HIDDEN. static void Main(string[] args) { string password = Console.ReadLine(); char[] notAllowedSymbols = { '!', '#', '
#x27;, '%', '&', '(', ')', '*', ',', '+', '-' }; //your code goes here char[] p = new char[100]; for (int i = 0;i< password.Length; i++) { p[i]= Convert.ToChar(password.Substring(i,1)); } for (int k = 0; k < p.Length; k++) { for (int j = 0; j<notAllowedSymbols.Length; j++) { if(p[k]==notAllowedSymbols[j]) { Console.Write("Invalid"); break; } } } Console.Write(""); }6 Réponses
+ 8
Faris Mohamed , please give a brief description of the task you want to solve. Thanks!
+ 5
Faris Mohamed , i think the issue is, that if multiple "not allowed Symbols" are in the password, the output "Invalid" also appears multiple times. This should not be, as stated in the last line of the task description.
the current break statement is leaving the inner for loop, but not the outer ones.Try to fix this.
+ 4
for(int i = 0; i < 10; i++)
{
if(password.Contains(notAllowedSymbols[i]))
{
Console.WriteLine("Invalid");
break;
}
}
+ 1
now that makes sense! Thank you so much!
0
i know there are other ways. but i am sure this way works too. but i couldnt find the error. just one hidden test case fail.
0
Brief description: All test cases passed except one which is hidden. So i couldn’t find the minor issues in my code or rather the logical flow. Greatly appreciate if someone could identify it.
Write a program to take the password as input and output "Invalid", if it contains any disallowed symbols.
If the password requirement is satisfied, program shouldn't output anything.
Sample Input
yl1893!dm$
Sample Output
Invalid
Hint
The message should be output only once regardless of how many disallowed symbols the password contains.