ach test case. The line is to contain the lexicographically smallest sequence
for the test case. 2
CGAGTCAGCT
CTCC
Sample Output:
AGCTCGAGTC
CCCT
Codes:
//#define LOCAL
#include <cstdio>
#include <cstring>
#define maxn 105
char s[maxn];
int less(const char* s, int p, int q) {
int n = strlen(s);
for(int i=0; i<n; ++i)
if(s[(p+i)%n] != s[(q+i)%n])
return s[(p+i)%n] < s[(q+i)%n];
return 0;
}
int main()
{
#ifdef LOCAL
freopen("E:\\Temp\\input.txt", "r", stdin);
freopen("E:\\Temp\\output.txt", "w", stdout);
#endif
int T;
scanf("%d", &T);
while(T--) {
scanf("%s", s);
int ans = 0;
int n = strlen(s);
for(int i=1; i<n; ++i)
if(less(s, i, ans)) ans = i;
for(int i=0; i<n; ++i)
putchar(s[(i+ans)%n]);
putchar('\n');
}
return 0;
}