【例题3-6 UVA - 1584】Circular Sequence
【链接】 我是链接,点我呀:)
【题意】
【题解】
不用真的把每一位都取出来。 用一个后缀的思想。 把原串复制一遍接在后面,然后把每个字符串 都当成一个长度为n的后缀就好了。 比较每个后缀就行了【错的次数】
在这里输入错的次数【反思】
在这里输入反思【代码】
#include <bits/stdc++.h>
using namespace std;
const int N = 100;
int n;
char s[N+10];
bool smaller(int p, int q)
{
for (int i = 0; i < n; i++)
if (s[(p + i) % n] != s[(q + i) % n])
return s[(p + i) % n] < s[(q + i) % n];
return 0;
}
int main()
{
//freopen("F:\\rush.txt", "r", stdin);
int T;
scanf("%d", &T);
while (T--)
{
scanf("%s", s);
n = strlen(s);
int ans = 0;
for (int i = 1; i < n; i++)
if (smaller(i, ans))
ans = i;
for (int i = 0; i < n; i++)
putchar(s[(ans + i) % n]);
puts("");
}
return 0;
}