I have to make an algorithm who compares two strings and returns a boolean.
it is true if all the letters of string a are present in string b.
for example "romain" and "marion" returns true.
"world" and "dlrow" returns true.
my code works only in case there is no duplicate and I don't understand why. Thank you for your help.
string a = @"aka";
string b = @"aka";
bool istwin(string x, string y)
{
int compteur = 0;
if (x.Count() == y.Count())
{
int index = x.Count();
for (int i = 0; i < index; i++)
{
for (int z = 0; z < index; z++)
{
Console.WriteLine(x[z] + " comparé à " + y[i]+"indexs : "+z+" , "+i);
if (x[z] == y[i])
{
compteur++;
}
}
}
Console.WriteLine();
Console.WriteLine(compteur);
if (compteur == index)
{
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
//istwin(a, b);
Console.WriteLine(istwin(a, b));
}
Enumerable.Intersect… could you please edit post to clarify expectations - what results should be for following pairs: {"aaa", "a"}, {"a", "aaa"}, {"a", "abc"}?