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.
Input
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
Output «YES», if it is possible to reverse some substring of s to make s equal to t, and «NO», otherwise.
Examples
Input
abcdefg abedcfg
Output
YES
Input
abcdefg abdecfg
Output
NO
看上去像水题 没看懂题意 问了一波师兄 最终发现是自己粗心 我自己以为字串是可以无限反转的
师兄说只能反转一次 然后就
水题啊!!!!
直接刚了;
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=2e5+10;
char str1[maxn],str2[maxn];
int main()
{
int l=0,r=0;
scanf("%s",str1);
scanf("%s",str2);
//reverse(str1+1,str1+4);
//printf("%s",str1+1);
int 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])
{
r=i;
break;
}
}
reverse(str2+l,str2+r+1);
//printf("%s",str2);
int flag=1;
for(int i=0;i<len;i++)
{
if(str1[i]!=str2[i])
{
flag=0;
break;
}
}
if(flag) printf("YES\n");
else printf("NO\n");
}