HDU6543 Can you raed it croretcly? (字符串匹配)[C++]

题目及翻译

题面

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?
翻译
你能看出标题的诡异吗?就算标题的单词拼错了,你还是能动那是什么意思。
研究表明,如果一个单词的首尾字母是正确的,只交换中间的其他字母,人类能够自动纠正这个单词。
现在题目提供给你一些单词和他们的正确拼写方式,你是否能够正确识别他们?

输入

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.
翻译
输入包括多组样例
每组样例占用一行,包含两个字符串,每个字符串只包含小写字母,并且长度不会超过20

输出

翻译
Output “Equal” when the two strings are same; output “Yes” when you can correct it, otherwise outoput “No”.
两个字符串相同时输出 “Equal”
可以自动识别第一个字符串时输出 “Yes”
其他的输出 “No”

输入样例

raed read
it it
croretcly correctly
raed dear

输出样例

Yes
Equal
Yes
No

题目思路

输入两个字符串,字符串匹配即可

注意事项

1.需要输出到文件尾
2.输出时可能会漏掉一些 “No” 的情况
3. “Equal” 的条件是字符串相等
4. “Yes” 的条件为①首尾字符相同②字符串字母一一对应

AC代码

C++

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
	static char a[25],b[25];
	static int lena,lenb;
	while(~scanf("%s %s",a,b))//输入到文件尾
	{
		lena=strlen(a);
		lenb=strlen(b);
		if(strcmp(a,b)==0)printf("Equal\n");
		else if(a[0]==b[0]&&a[lena-1]==b[lenb-1])//判断首尾相同
		{
			sort(a,a+lena);
			sort(b,b+lenb);
			if(strcmp(a,b)==0)printf("Yes\n");//排序后再比较可以得知每个字母是否一一对应
			else printf("No\n");//这个No的输出可能被忽略,我wa数次就是没发现这个
		}
		else printf("No\n");
	}
	return 0;
}

本文作者 CSDN@扶她小藜
个人主页链接 https://blog.csdn.net/weixin_44579869

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值