- 1
c# working with strings practice.
The problem is as follows: You are creating an authentication system. The password shouldn't contain any of these symbols: char[] notAllowedSymbols = { '!', '#', '
#x27;, '%', '&', '(', ')', '*', ',', '+', '-' }; CS The given program takes the password as input. Task Write a program to 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. and here is my code: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { string password = Console.ReadLine(); char[] notAllowedSymbols = { '!', '#', '#x27;, '%', '&', '(', ')', '*', ',', '+', '-' }; if (password.Length == 0) { Console.WriteLine("Invalid"); } else for(int i = 0; i < password.Length; i++) { for(int j = 0; j < 11; j++) { if(notAllowedSymbols[j] == password[i]) { Console.WriteLine("Invalid"); break; } } } } } } Here's the kicker, there are 5 test cases, I passed 4/5. I added the if (password.Length == 0) just in case it was being sneaky. the biggest problem really, is that I can't see what word was passed through the test because its locked. anyone pass this and know what I did wrong? Thank you!4 Respostas
+ 1
Hi guys ,It's work for me
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace SoloLearn
{
class Program
{
static void Main(string[] args)
{
string password = Console.ReadLine();
char[] notAllowedSymbols = { '!', '#', '#x27;, '%', '&', '(', ')', '*', ',', '+', '-' };
//your code goes here
for(int i= 0;i<notAllowedSymbols.Length;i++)
{
if(password.Contains(notAllowedSymbols[i])){
Console.WriteLine("Invalid");
break;
}
else{}
}
}
}
}
0
ignore me please i'm a dummy. the break wasn't sufficient to stop it from printing multiple times. I figured it out.
0
Awesome that you figured it out yourself! Great job
0
It's work for me
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace SoloLearn
{
class Program
{
static void Main(string[] args)
{
string password = Console.ReadLine();
char[] notAllowedSymbols = { '!', '#', '#x27;, '%', '&', '(', ')', '*', ',', '+', '-' };
if (password.Length == 0)
{
Console.WriteLine("Invalid");
}
else
for (int i = 0; i < notAllowedSymbols.Length; i++)
{
if (password.Contains(notAllowedSymbols[i]))
{
Console.WriteLine("Invalid");
break;
}
}
}
}
}