1 条题解
-
1HLBhahaqiu LV 8 MOD @ 2020-08-30 21:51:00
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map>
using namespace std;char rd; int pn;
template<typename Type>
inline void read(Type& v)
{
pn=1;
while((rd=getchar())<'0'||rd>'9')
if(rd=='-')
pn=-1;
v=rd-'0';
while((rd=getchar())>='0'&&rd<='9')
v=v*10+rd-'0';
v*=pn;
}
template<typename Type>
inline void out(Type v,bool c=1)
{
if(v==0)
putchar(48);
else
{
if(v<0)
{
putchar('-');
v=-v;
}
int len=0,dg[20];
while(v>0)
{
dg[++len]=v%10;
v/=10;
}
for(int i=len;i>=1;i--)
putchar(dg[i]+48);
}
if(c)
putchar('\n');
else
putchar(' ');
}const int MAXN=100005;
char a[MAXN<<1];
int n;void init()
{
read(n);
char ch;
for(int i=1;i<=n;i++)
{
ch=getchar();
if(ch!='\n')
a[i]=ch;
else
i--;
}
for(int i=1;i<=n;i++)
a[i+n]=a[i];
a[(n<<1)+1]='\0';
}void work()
{
int i=1,j=2;
while(i<=n&&j<=n)
{
int k=0;
while(k<=n&&a[i+k]==a[j+k])
k++;
if(k==n)
{
cout<<0<<endl;
return;
}
if(a[i+k]>a[j+k])
{
i=i+k+1;
if(i==j)
j++;
}
else
{
j=j+k+1;
if(i==j)
i++;
}
}
int ans=min(i,j);
out(ans-1);
}int main()
{
init();
work();
return 0;
}
- 1