-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathA_Comparing_Strings.cpp
64 lines (61 loc) · 1.16 KB
/
A_Comparing_Strings.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include<bits/stdc++.h>
#define ll long long
#define INF (1LL << 60)
#define inf 1<<30
const long long mod=1e9 +7;
using namespace std;
vector<int> sieve(int n){
vector<bool> vec(n+1,true);
vec[0]=vec[1]=false;
for(int i=2;i<n+1;i++){
if(vec[i]==true){
for(int j=2*i;j<n+1;j+=i){
vec[j]=false;
}
}
}
vector<int> ans;
for(int i=0;i<n+1;i++){
if(vec[i]){
ans.push_back(i);
}
}
return ans;
}
void solve(){
string a,b;
cin>>a>>b;
int count=0;
if(a.size()!=b.size()){
cout<<"NO"<<"\n";
return;
}
int first_index=-69;
int second_index=-68;
for(int i=0;i<a.size();i++){
if(a[i]!=b[i]){
if(first_index==-69){
first_index=i;
}
else{
second_index=i;
}
count++;
}
}
if(count==1|| count>2){
cout<<"NO"<<"\n";
return;
}
swap(a[first_index],a[second_index]);
if(a==b){
cout<<"YES"<<"\n";
}
else{
cout<<"NO"<<"\n";
}
}
int main(){
solve();
return 0;
}