可惜没如果=_=
时光的河入海流

 

 看到环形,首先想到乘两倍拆成线性;

对于这种固定长度的子串比较,对每一个子串,可以考虑通过第一个字符的位置进行标记。

还有UVA竟然禁止用gets,所以此题只能用fgets,记住fgets会把行末回车读进来,所以算长度的时候应该-1;

 1 #include "bits/stdc++.h"
 2 using namespace std;
 3 const int MAX=205;
 4 int t,ls,ans;
 5 char s[MAX];
 6 bool check(int x,int y){
 7     int i,j;
 8     for (i=0;i<ls;i++){
 9         if (s[x+i]!=s[y+i])
10             return s[x+i]<s[y+i];
11     }
12 }
13 int main(){
14     freopen ("circular.in","r",stdin);
15     freopen ("circular.out","w",stdout);
16     int i,j;
17     scanf("%d\n",&t);
18     while (t--){
19         fgets(s+1,105,stdin);
20         ls=strlen(s+1)-1;ans=1;
21         for (i=1;i<=ls;i++)
22             s[i+ls]=s[i];
23         for (i=2;i<=ls;i++)
24             if (check(i,ans))
25                 ans=i;
26         for (i=0;i<ls;i++)
27             putchar(s[i+ans]);
28         putchar('\n');
29     }
30     return 0;
31 }

 

posted on 2020-10-18 11:24  珍珠鸟  阅读(121)  评论(0编辑  收藏  举报