Time limit per test
2 seconds
Memory limit per test
256 megabytes
Input
Standard Input
Output
Standard output
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 shoshould write a thesis on genome. dwarven genome is far from simple. it is represented
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 ".
Sample test (s) Input
abba
Output
YES
Input
aaab
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 ".
Problem description: This is to determine whether a string can be changed to another string by adjusting the order of the two letters. You can first calculate the difference between the original two strings to see if there are only two locations with different letters, then sort the letters in these two strings from small to large to see if they can be the same. If the original string is indeed only two different positions and the last two strings are the same, then it is proved that it can be obtained through transformation.
#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;}