Do you feel weird when reading the problem title? You can understand word meanning correctly even if its spelling is wrong.
According to research, if the initial and last letter of the word are right, and just swap the others, human can correct the spelling of the word automatically.
Now, giving you a word and its correct spelling, can you correct it automatically?
Input
The input contains several test cases.
Each test case consists of one line with two strings, each string only contains lowercase letter, and its length is no more than 20.
Output
Output "Equal" when the two strings are same; output "Yes" when you can correct it, otherwise outoput "No".
Sample Input
raed read it it croretcly correctly raed dear
Sample Output
Yes Equal Yes No
#include <iostream>
#include <bits/stdc++.h>
#include <string.h>
using namespace std;
int main()
{
char n[25],m[25];
int a,b,s[200],ss[200],i;
while(cin >> n >> m)
{
memset(s,0,sizeof(s));
memset(ss,0,sizeof(ss));
a=strlen(n);
b=strlen(m);
if(n[0]==m[0]&&n[a-1]==m[b-1])
{
if(strcmp(n,m)==0)
{
cout << "Equal" << endl;
}
else
{
for(i=1;i<=a-2;i++)
{
s[n[i]]++;
}
for(i=1;i<=b-2;i++)
{
ss[m[i]]++;
}
for(i=97;i<=97+32;i++)
{
if(s[i]!=ss[i])
{
break;
}
}
if(i!=97+33)
{
cout << "No" << endl;
}
else
{
cout << "Yes" << endl;
}
}
}
else
{
cout << "No" << endl;
}
}
return 0;
}