A. Comparing Strings
来源:互联网 发布:网络布线桥架 编辑:程序博客网 时间:2024/06/07 16:31
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.
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.
Print "YES", if the dwarves belong to the same race. Otherwise, print "NO".
abba
YES
aaab
NO
- 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 <iostream>#include <cstdio>#include <cstdlib>#include <cmath>#include <cstring>#include <string>#include<set>#include <algorithm>using namespace std;int main() { string a, b;int i,c=0; cin >> a >> b; for (i = 0; i < a.size() && i < b.size(); i++) { if(a[i] != b[i]){c++;} } sort(a.begin(), a.end()); sort(b.begin(), b.end());if(a==b&&c==2){printf("YES\n");}else{printf("NO\n");}return 0;}
- A. Comparing Strings
- Comparing Strings
- Comparing Strings
- Comparing strings (C)
- Java源码-字符串大小比较(Comparing Strings)
- A. Comparing Two Long Integers
- comparing strings in PHP with the == operator
- CodeForces 616A Comparing Two Long Integers
- CF Comparing Two Long Integers 616A
- cf 616A Comparing Two Long Integers
- CodeForces 616A Comparing Two Long Integers
- CodeForces 616A Comparing Two Long Integers
- CodeForces 616A Comparing Two Long Integers
- Java源码-判断两个字符串的子字符串是否匹配(Comparing Portions of Strings)
- Comparing JSValue representations in JavaScriptCore. A short overview
- Educational Codeforces Round 5 A. Comparing Two Long Integers
- CodeForce 616A Comparing Two Long Integers 字符串比较
- CodeForces 616 A. Comparing Two Long Integers(水~)
- Wireshark抓包工具使用教程以及常用抓包规则
- EditText 长按弹出的上下文菜单(如何修改系统默认弹出的上下文菜单)
- 分享一个自定义的SlidingDrawer,可控大小。
- UML 类图. 对象图. 接口图. 用例图 .包,参与者. 依赖关系. 泛化/继承关系. 关联关系 .聚合/聚集关系. 实现关系 组合关系。
- android init.rc中的service
- A. Comparing Strings
- sgu 174 Walls (并查集)
- 矩阵操作
- 利用 Chrome 的打印功能将网页保存为 PDF
- 发布复杂的WebService
- 直线拟合,图像组件轮廓的检测和计算机描述
- 【xinfanqie】笔者支招:熟知Word打印的六大技巧
- Java窗体设计中控件的值自动清除的原因与解决方法
- 宏定义与使用分析