CodeForces - 186A-Comparing Strings

Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome is far from simple. It is represented by a string that consists of lowercase Latin letters.

Dwarf Misha has already chosen the subject for his thesis: determining by two dwarven genomes, whether they belong to the same race. Two dwarves belong to the same race if we can swap two characters in the first dwarf's genome and get the second dwarf's genome as a result. Help Dwarf Misha and find out whether two gnomes belong to the same race or not.

Input

The first line contains the first dwarf's genome: a non-empty string, consisting of lowercase Latin letters.

The second line contains the second dwarf's genome: a non-empty string, consisting of lowercase Latin letters.

The number of letters in each genome doesn't exceed 105. It is guaranteed that the strings that correspond to the genomes are different. The given genomes may have different length.

Output

Print "YES", if the dwarves belong to the same race. Otherwise, print "NO".

Examples

Input

ab
ba

Output

YES

Input

aa
ab

Output

NO

Note

  • First example: you can simply swap two letters in string "ab". So we get "ba".
  • Second example: we can't change string "aa" into string "ab", because "aa" does not contain letter "b".

题解:题目大意是让你判断是否能通过换两个字母的位置是否一样

代码:

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>

using namespace std;

int main()
{
    char s1[100005],s2[100005];
   scanf("%s%s",s1,s2);
	int flag=0;
	int a[100005];
	int temp=0;
	for(int t=0;t<strlen(s1);t++)
	{
		
		if(strlen(s1)!=strlen(s2))
		{
			flag=3;
		}
	    if(s1[t]!=s2[t])
		{
	       a[temp]=t;
	       temp++;
		flag++;
		if(flag==3)
		break;
	    }
	    else
	    continue;
	}	
	if(flag==2)
	{
		if(s1[a[0]]==s2[a[1]]&&s1[a[1]]==s2[a[0]])
		{
			printf("YES\n");
		}
		else
		{
			printf("NO\n");
		}
	}
	else
	{
		printf("NO\n");
	}
	
	return 0;
} 

 

转载于:https://www.cnblogs.com/Staceyacm/p/10781970.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值