E - Substring Reverse Gym - 101755E 國外區域賽
阿新 • • 發佈:2018-11-30
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"); }