• Source
    1. #include <iostream>
    2. #include <string>
    3. #include <algorithm>
    4. using namespace std;
    5. int main()
    6. {
    7. int t;
    8. cin>>t;
    9. for(int k=1;k<=t;++k)
    10. {
    11. string s;
    12. cin>>s;
    13. string s1=s;
    14. bool ans=false;
    15. for(int i=0;i<s.size()-1;++i)
    16. if(s[i]<s[i+1])
    17. ans=true;
    18. if(!ans)
    19. cout<<"no answer"<<endl;
    20. else
    21. {
    22. next_permutation(s1.begin(),s1.end());
    23. cout<<s1<<endl;
    24. }
    25. }
    26. }