水题

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".

Example
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<stdio.h>
#include<string.h>
#define N 100010
int main()
{
    char a[N],b[N],x[10],y[10];
    int c=0,i;
    long int m,n;
    gets(a);
    gets(b);
    m=strlen(a);
    n=strlen(b);
    if(m!=n)
    {
        printf("NO\n");
        return 0;
    }
    for(i=0;i<m;i++)
    {
        if(c==3)
        {
            break;
        }
        if(a[i]!=b[i])
        {
            x[c]=a[i];
            y[c]=b[i];
            c++;
        }
    }
    if(c==2&&x[0]==y[1]&&y[0]==x[1])
    {
        printf("YES\n");
    }
    else printf("NO\n");
    return 0;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值