然后就没有然后了。
然后要用unsigned char
=-=。。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define maxn 20000010
using namespace std;
unsigned char s[maxn];
int n;
int solve(){
int i = 1, j = 2, N = n << 1;
while(i < n && j < n){
int k = 0;
while(s[i + k] == s[j + k] && k < n)k ++;
if(k == n)return min(i, j);
if(s[i + k] > s[j + k])i = max(j + 1, i + k + 1);
else j = max(i + 1, j + k + 1);
}
if(i < n)return i;
return j;
}
int main(){
scanf("%d", &n);
unsigned char ch = getchar();
for(; ch < '!'; ch = getchar());
for(int i = 1; i <= n; i ++){
s[i] = ch;
ch = getchar();
}
for(int i = 1; i <= n; i ++)
s[i + n] = s[i];
int st = solve();
for(int i = st; i < st + n; i ++)
putchar(s[i]);
return 0;
}