+ 1

It's a Sign WORKS WRONG?

my code sample 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[] input = Console.ReadLine().Split(" "); foreach (string s in input) { if(IsPolinom(s)) { Console.WriteLine("Open"); return; } } Console.WriteLine("Trash"); } static bool IsPolinom(string s) { char[] arr = s.ToCharArray(); Array.Reverse(arr); return new string(arr)==s; } } } Why it can't pass all tests?

22nd May 2020, 11:14 AM
Роман Львов
Роман Львов - avatar
4 Réponses
0
No. Logic of test is if one of word in array is polynomial then Open.That's why no need to end foreach search if true. If we can't find Polynom then Trash. But my issue not working on test 3 and 5.
22nd May 2020, 11:51 AM
Роман Львов
Роман Львов - avatar
0
static void Main(string[] args) { string[] x = new string[4]; int i; for (i = 0; i < 4; i++) { x[i] = Console.ReadLine().Trim(); } foreach (string s in x) { if (IsPolinom(s)) { Console.WriteLine("Open"); return; } } Console.WriteLine("Trash"); } static bool IsPolinom(string s) { char[] arr = s.ToCharArray(); Array.Reverse(arr); return new string(arr) == s; }
27th Oct 2021, 7:03 AM
Роман Жигунов
Роман Жигунов - avatar
0
чуть-чуть доделал)
27th Oct 2021, 7:04 AM
Роман Жигунов
Роман Жигунов - avatar
- 2
Guess you might wanted this? foreach (string s in inputs) { if(IsPolinom(s)) { Console.WriteLine("Open"); return; } else { Console.WriteLine("Trash"); } }
22nd May 2020, 11:44 AM
Sandra Meyer
Sandra Meyer - avatar