Algorithm


A. Comparing Strings
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 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
Copy
ab
ba
output
Copy
YES
input
Copy
aa
ab
output
Copy
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".



 

Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming

#include <bits/stdc++.h>

using namespace std;

int fr[26];
string a, b;

int main() {
  cin >> a >> b;

  if(a.length() != b.length()) {
    puts("NO");
    return 0;
  }

  int cnt = 0;
  for(int i = 0; i < a.length(); ++i)
    if(a[i] != b[i])
      ++cnt, ++fr[a[i] - 'a'], ++fr[b[i] - 'a'];
  
  if(cnt != 2) {
    puts("NO");
  } else {
    bool ok = true;
    for(int i = 0; i < 26; ++i)
      if(fr[i] % 2 != 0)
        ok = false;
    if(ok)
      puts("YES");
    else
      puts("NO");
  }

  return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
ab ba

Output

x
+
cmd
YES
Advertisements

Demonstration


Codeforcess Solution Comparing Strings, A. Comparing Strings ,C,C++, Java, Js and Python ,Comparing Strings,Codeforcess Solution

Previous
Codeforces solution 1080-B-B. Margarite and the best present codeforces solution
Next
CodeChef solution DETSCORE - Determine the Score CodeChef solution C,C+