"Deja Vu" task for C# | Sololearn: Learn to code for FREE!

0

"Deja Vu" task for C#

Input Format: A string of random letter characters (no numbers or other buttons were pressed). Output Format: A string that says 'Deja Vu' if any letter is repeated in the input string, or a string that says 'Unique' if there are no repeats. 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 w = Convert.ToString(Console.ReadLine()); string result = "Unique"; for (int i = 0; i == w.Length - 2 || result == "Deja Vu"; i++) { for (int j = 1; j == w.Length - i - 1; j++) { if(w[i] == w[i + j]) { result = "Deja Vu"; } else {continue;} } } Console.Write(result); } } }

1/30/2020 1:43:26 AM

Golden Flower

3 Answers

New Answer

+1

Your inner loop is trying to check elements before i, so the initial conditions should be 0 for j and 1 for i. and the comparison should be w[j] == w[j+i] try using "sololearn" as example and go through the variable changes in each iteration and you can see

+1

I finally made the correct code 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 w = Convert.ToString(Console.ReadLine()); string result = "Unique"; for (int i = 0; i < w.Length - 1; i++) { for (int j = 1; j < w.Length - i; j++) { if(w[i] == w[j + i]) { result = "Deja Vu"; } } } Console.Write(result); } } }

0

I am noob, so I tried to understand why this won't work, but hopelessly. Doesn't for loop work like that?