水题
2018-02-15 21:08
197 查看
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.
InputThe 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.
OutputPrint "YES", if the dwarves belong to the same race. Otherwise, print "NO".
ExampleInput
Second example: we can't change string "aa" into string "ab", because "aa" does not contain letter "b".
此题就是判断一个字符串能否通过调整其中两个字母的顺序变成另外一个字符串,可以先统计原始两个字符串中不一样的地方,看看是否只有两个位置字母不同,然后看是否相同。
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.
InputThe 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.
OutputPrint "YES", if the dwarves belong to the same race. Otherwise, print "NO".
ExampleInput
ab baOutput
YESInput
aa abOutput
NONoteFirst 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 ,b ,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; }
相关文章推荐
- HDOJ 2041 超级楼梯(水题)(规律)
- hdu 1084 What Is Your Grade? -水题
- HDU 2111--Saving HDU【贪心水题】
- POJ2017 ZOJ2176 UVALive3059 Speed Limit【水题】
- 杭电2073无限的路.水题
- Smarandache consecutive number Ⅱ (HNUST 1706 字符串转化水题)
- hdu5253 连接的管道 最小生成树水题
- HDU 1001 Sum Problem(水题)
- 杭电 2549 壮志难酬 水题
- EOJ Monthly 2018.1 - A 石头剪刀布的套路 (水题)
- POJ 1861 && ZOJ 1542--Network 【最小生成树 && kruscal && 水题】
- CodeForces 916A Jamie and Alarm Snooze (水题)
- POJ 2014:Flow Layout 模拟水题
- CodeForces - 231D (计算几何. 水题)
- Codeforces Round #316 (Div. 2) -B-Simple Game-水题
- LeetCode | 766. Toeplitz Matrix矩阵操作水题
- hdu 1877 Java 水题系列
- 紫书第八章-----高效算法设计(快速排序水题格式要求严)
- Codeforces Gym 100431D Bubble Sort 水题乱搞
- 水题堆1.C 人见人爱A^B