-
Notifications
You must be signed in to change notification settings - Fork 2
/
comparing_strings.cpp
45 lines (42 loc) · 1.01 KB
/
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
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
string s1,s2;
cin>>s1>>s2;
int count1=0,count2=0;
if(abs(s1.length()-s2.length())>0)
cout<<"NO"<<endl;
else
{
count1 = 0;
count2 = 0;
char a,b;
for (int i=0; i<s1.length(); i++)
{
if (s1[i] != s2[i])
{
++count1;
if (count1 == 1)
{
a = s1[i];
b = s2[i];
}
else if (count1 == 2)
{
if (s1[i] == b && s2[i] == a)
count2 = 1;
}
else
break;
}
}
if (count2 == 1 && count1 == 2)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
return 0;
}