#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <map>
#include <cctype>
using namespace std;
char str[200010];
char str2[100010];
int main()
{
//freopen("in.txt","r",stdin);
int T,L;
scanf("%d",&T);
while(T--)
{
scanf("%d %s",&L,str);
int len=strlen(str);
strcpy(str2,str);
strcat(str,str2);
int i,j,k;
i=0;j=1;k=0;
while(k<len&&i<len&&j<len)
{
if(str[i+k]==str[j+k])
{
k++;
}
else
{
if(str[i+k]>str[j+k])
{
i=i+k+1;
if(i==j)
i++;
}
else
{
j=j+k+1;
if(i==j)
j++;
}
k=0;
}
}
printf("%d\n",i<j?i:j);
}
return 0 ;
}
ZOJ 1729 Hidden Password
最新推荐文章于 2018-11-12 20:42:01 发布