K
keeponfalling
Guest
I need to determine whether each character in the first string can be uniquely replaced by a character in the second string so that the two strings are equal.
Like this:
for "eef" and "ddg"
Result :
True
e => d
f =>g
If I have: "efe" and "ddg" the result is "False" because "e" it has "d" and "g" . (strings are equal in lenght)
string firstWord = Console.ReadLine();
string secondWord = Console.ReadLine();
char[] firstPhraseChars = new char[firstWord.Length];
char[] secondPhraseChars = new char[secondWord.Length];
int charsCount = 0;
for (int i = 0; i< firstWord.Length && i< secondWord.Length; i+=2)
{
char first = firstWord;
char firstofSecond = secondWord;
for(int j = i+1; j< firstWord.Length && j<secondWord.Length; j++,i++)
{
char second = firstWord[j];
char secondofSecond = secondWord[j];
if (first == second && firstofSecond == secondofSecond)
{
firstPhraseChars[charsCount] = firstWord;
secondPhraseChars[charsCount] = secondWord;
charsCount++;
break;
}
}
}
for (int a = 0; a < firstPhraseChars.Length -1; a++)
{
if ((firstWord.IndexOf(firstPhraseChars[a]) >= 0) && (secondWord.IndexOf(secondPhraseChars[a]) >= 0))
{
Console.WriteLine(true);
Console.WriteLine(firstPhraseChars[a] + " => " + secondPhraseChars[a]);
}
if((firstWord.IndexOf(firstPhraseChars[a]) < 0) && (secondWord.IndexOf(secondPhraseChars[a]) < 0))
{
Console.WriteLine(firstPhraseChars[a] + " => " + secondPhraseChars[a]);
}
}
Console.WriteLine(false);
Continue reading...
Like this:
for "eef" and "ddg"
Result :
True
e => d
f =>g
If I have: "efe" and "ddg" the result is "False" because "e" it has "d" and "g" . (strings are equal in lenght)
string firstWord = Console.ReadLine();
string secondWord = Console.ReadLine();
char[] firstPhraseChars = new char[firstWord.Length];
char[] secondPhraseChars = new char[secondWord.Length];
int charsCount = 0;
for (int i = 0; i< firstWord.Length && i< secondWord.Length; i+=2)
{
char first = firstWord;
char firstofSecond = secondWord;
for(int j = i+1; j< firstWord.Length && j<secondWord.Length; j++,i++)
{
char second = firstWord[j];
char secondofSecond = secondWord[j];
if (first == second && firstofSecond == secondofSecond)
{
firstPhraseChars[charsCount] = firstWord;
secondPhraseChars[charsCount] = secondWord;
charsCount++;
break;
}
}
}
for (int a = 0; a < firstPhraseChars.Length -1; a++)
{
if ((firstWord.IndexOf(firstPhraseChars[a]) >= 0) && (secondWord.IndexOf(secondPhraseChars[a]) >= 0))
{
Console.WriteLine(true);
Console.WriteLine(firstPhraseChars[a] + " => " + secondPhraseChars[a]);
}
if((firstWord.IndexOf(firstPhraseChars[a]) < 0) && (secondWord.IndexOf(secondPhraseChars[a]) < 0))
{
Console.WriteLine(firstPhraseChars[a] + " => " + secondPhraseChars[a]);
}
}
Console.WriteLine(false);
Continue reading...