Can you raed it croretcly?(模拟)

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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值