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); } } }
3 Answers
+ 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?
Hot today
I have made a calculator in which my % (Percentage) not work correctly for 100%50 or 100%20.
2 Votes
Python palindrome challenge.
1 Votes
Java
0 Votes
Number of Ones ( C++ ) question!
1 Votes