先是tl, 然后是wr ,各位高手请帮帮忙,这里是code;
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<fstream>
using namespace std;
int flag1[10000],flag2[10000];
main(){

int n,i,j,k,len,nf,temp,l1,l2,l3;
char chf,chs,prime;
string s;
cin>>n;
getline(cin,s); //get the characther of enter
for(k=0;k<n;++k){
getline(cin,s);
len=s.size();
chf='z';
for(i=0;i<len;++i)
if(s[i]<chf) chf=s[i]; //get the smallest alpha of string
prime = chf; //store the prime char
l1=l2=0; //initiate the length of the flags
chs='z'; //store the next smallest alpha
for(i=0;i<len;++i){
if(s[i]==chf&&s[(i-1+len)%len]!=chf){
flag1[l1++]=i;
if(s[(i+1)%len]<chs) chs=s[(i+1)%len];
}
}
if(l1==0) { cout<<'1'<<endl; continue;}
if(l1==1) { cout<<flag1[0]+1<<endl; continue; }
//**********************do if the satiuation is not satisfide*********************
copy(flag1,flag1+l1,flag2);
l2=l1; l1=0;
chf=chs; chs='z';
for(j=1;j<=len;++j){
for(i=0;i<l2;++i){
if( s[(flag2[i]+j)%len]==chf){
if(chf==prime&&s[ (flag2[i]+len-j)%len ]!=prime||chf!=prime){
flag1[l1++]=flag2[i];
if(s[ (flag2[i]+j+1)%len]<chs) chs=s[(flag2[i]+j+1)%len] ;
}//end if chf
}//end if s
}//end for i
if(l1==0) { cout<<flag2[0]+1<<endl; break; }
if(l1==1) { cout<<flag1[0]+1<<endl; break; }
if(l1==l2&&l1*j==len) {cout<<flag1[0]+1<<endl; break;}
copy(flag1,flag1+l1,flag2);
l2=l1; l1=0;
chf=chs; chs='z';
}
}//end for k
}