#include<stdio.h>
#include<string.h>
int main(){
char a[1000],b[1000],d[1000];
int n;
scanf("%d",&n);
int i,j,k;
for(i=0;i<n;i++){ //这是将所有的都循环;
scanf("%s",a);
int s=0;
char min='T';
while(a[s]!='\0'){ //找到其中最小的的值;
if(a[s]<min){
min=a[s];
}
d[s]=a[s];
s++;
}
int c[100],z=0;
for(j=0;j<s;j++){ //找到最小的位置;
if(a[j]==min){
c[z]=j;
z++;
}
}
int x=0,y=0;
for(x=0;x<z;x++){ //连接并比较大小;
for(j=c[x];j<s;j++){
b[y]=a[j];
y++;
}
for(j=0;j<c[x];j++){
b[y]=a[j];
y++;
}
if(strcmp(d,b)>0){
strcpy(d,b);
}
y=0;
}
d[s]='\0'; //封装,防泄漏;
puts(d);
}
return 0;
}
其思路还是很好懂。