3-6环形序列(Circular Sequence,AMC/ICPC Seoul 2004, UVa1584
#include
#include
using namespace std;
int main()
{
int T;
cin >> T;
while (T-- > 0)
{
string org;
cin >> org;
int n = org.size();
string smallest = org;
for (int i = 1; i < n; ++i)
{
string temp(&org[i], &org[n - 1] + 1);
temp.append(&org[0], &org[i]);
if (smallest > temp)
smallest = temp;
}
cout << smallest << endl;
}
}