Code: Select all
#include<iostream>
#include<cstring>
using namespace std;
char *createStr(char str[], int pos)
{
char temp[120];
int len = strlen(str);
for(int i=0;i<len;i++)
{
temp[i] = str[(i+pos)%len];
}
temp[len] = NULL;
return temp;
}
char *detectOutput(char str[])
{
int len = strlen(str);
char temp[120], tempF[120];
strcpy(tempF, str);
for(int i=0;i<len;i++)
{
strcpy(temp, createStr(str, i));
if(strcmp(temp, tempF) < 0)
strcpy(tempF, temp);
}
return tempF;
}
int main()
{
int test;
char str[120];
char temp[120];
cin >> test;
while(test--)
{
cin >> str;
strcpy(temp, detectOutput(str));
cout << temp << endl;
}
return 0;
}