1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
#include <iostream> #include <string> using namespace std; int main() { string s,s1,p; int t; cin>>t; /*if("CCTC" > "CCCT") cout<<"CCTC"<<"\n"; else cout<<"CCCT"<<"\n"; */ while(t--) { cin>>s; p=s; for(int i=1;i<p.size();i++) { s1=""; s1.append(1u,p[i]); if((i+1)<p.size()) for(int j=i+1;j<p.size();j++) s1.append(1u,p[j]); if(s1.size()!=p.size()) { for(int k=0;k<i;k++) s1.append(1u,p[k]); } //cout<<s1<<" = s1\n"; if(s1<s) s = s1; } cout<<s<<"\n"; } return 0; } |