Working with Strings | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
0

Working with Strings

string password = Console.ReadLine(); char[] notAllowedSymbols = { '!', '#', '

#x27;, '%', '&', '(', ')', '*', ',', '+', '-' }; //your code goes here foreach (var item in password) { for (int i = 0; i < notAllowedSymbols.Length; i++) { if (item == notAllowedSymbols[i]) { Console.WriteLine("invalid"); break; } } } here's my code and i can't figure out why it doesn't run on the last test case of the working with strings problem, it works in 4/5 cases

23rd Jun 2021, 1:22 AM
Munene Rwigi
Munene Rwigi - avatar
6 ответов
+ 1
The thing is, you have to iterate through the symbols first and only then iterate through the password length. for(int x=0 ; x<notAllowedSymbols.Length ; x++){ if(password.Contains(notAllowedSymbols[x])){ Console.WriteLine("Invalid"); break; } }
24th Jan 2023, 11:29 AM
Rea
Rea - avatar
0
Please provide the description of this code coach. Also, please don't copy your code into the tags.
23rd Jun 2021, 1:57 AM
你知道規則,我也是
你知道規則,我也是 - avatar
0
sorry about that, that was my bad this is the description; 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.
23rd Jun 2021, 2:06 AM
Munene Rwigi
Munene Rwigi - avatar
0
According to the description you provided, unless the program want "Invalid" rather than "invalid", your code looks fine. If you have modified or shortened the question description, please provide a full one.
23rd Jun 2021, 2:12 AM
你知道規則,我也是
你知道規則,我也是 - avatar
0
I haven't shortened it but i could provide the hint; The message should be output only once regardless of how many disallowed symbols the password contains. My code does this too so i'm not sure what the last test case is testing to fail.
23rd Jun 2021, 2:21 AM
Munene Rwigi
Munene Rwigi - avatar
- 1
Try to change "invalid" to "Invalid" in your code then.
23rd Jun 2021, 2:27 AM
你知道規則,我也是
你知道規則,我也是 - avatar