Problem Description
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
思路:这题就是一个模拟题,大概的题意如下
给你两个字符串,如果一样就输出Equal
如果第一个字符串的第一个字符和第二个字符串的首字符不一样,或者第一个和第二给字符串最后一个字符不一样就输出N o
接下来就是如果前面的条件满足了,如果两个字符串中每种字符的数量一样输出Yes
否者输出No
后面我用到了对字符串的sort函数,这样也可以方便我们比较两个字符串中每种字符的数量是否相等。
sort(s.begin(),s.end());
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s1,s2;
while(cin>>s1>>s2)
{
char a=s1[0],b=s2[0];
char c=s1[s1.length()-1],d=s2[s1.length()-1];
if(s1==s2)
{
cout<<"Equal"<<endl;
continue;
}
if(a!=b||c!=d||s1.length()!=s2.length())
{
cout<<"No"<<endl;
continue;
}
if(a==b&&c==d&&s1.length()==s2.length())
{
int flag=0;
sort(s1.begin(),s1.end());
sort(s2.begin(),s2.end());
for(int i=0;i<s1.length();i++)
{
if(s1[i]!=s2[i])
{
flag=1;
break;
}
}
if(flag==1)
cout<<"No"<<endl;
else
cout<<"Yes"<<endl;
}
}
return 0;
}