Problem DescriptionA国认为如果字符串a可以通过操作X变成字符串b,就认为是一样的字符串。
操作X:将字符串分为两部分,然后调换位置,操作次数不限。W=xy,W’=yx。
Input有多组测试数据,处理到文件结尾。每组测试数据包含两个个字符串(包含英文字符和数字,长度为[1,500000])。
Output对于每组测试数据,如果两个字符串是相同的,输出Yes或者是No。
Sample Input
Sample Output
思路:就是将第一个字符串旋转,看能不能得到第二个字符串
AC代码:
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
string str1, str2;
while(cin >> str1 >> str2) {
int i, len = str1.size(), len2 = str2.size();
str1 += str1;
for(i=0; i < len; i++)
if(str1[i] == str2[0]) {
int t = 0;
while(str1[i + t] == str2[t]) t++;
if(t == len2) break;
}
if(i<len) printf("Yes\n");
else printf("No\n");
}
return 0;
}
原文:http://blog.csdn.net/u014355480/article/details/43534883