Two strings s and t of the same length are given. Determine whether it is possible to make t from s using exactly one reverse of some its substring.
The first line contains the string s, and the second — the string t. Both strings have the same length from 1 to 200000 characters and consist of lowercase Latin letters.
Output «YES», if it is possible to reverse some substring of s to make s equal to t, and «NO», otherwise.
abcdefg abedcfg
YES
abcdefg abdecfg
NO
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<map>
#include<iostream>
#include<algorithm>
#include<set>
#include<vector>
#include<queue>
#include<ctime>
#include<stack>
#define PI 3.14159265358797832384626
using namespace std;
int main()
{
char str1[200020],str2[200020],str3[200020];
while (~scanf("%s%s",str1,str2))
{
if(strcmp(str1,str2)==0)
{
printf("YES\n");
continue;
}
int l,f,len=strlen(str1);
for(int i=0; i<len; i++)
{
if(str1[i]!=str2[i])
{
l=i;
break;
}
}
for(int i=len-1; i>=0; i--)
{
if(str1[i]!=str2[i])
{
f=i;
break;
}
}
strcpy(str3,str1);
for(int i=l,j=f;i<=f;i++,j--)
{
str3[i]=str1[j];
}
if(strcmp(str3,str2)==0)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}