fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. int t;
  6. cin>>t;
  7. while(t--)
  8. { vector<string>a;
  9. vector<string>::iterator it;
  10. string s;
  11. cin>>s;
  12. string x=s;
  13. sort(s.begin(),s.end());
  14. a.push_back(s);
  15. while(next_permutation(s.begin(),s.end()))
  16. a.push_back(s);
  17. for(it=a.begin();*it!=x;it++) ;
  18. it=it+1;
  19.  
  20. cout<<*it<<endl;
  21. }
  22. return 0;
  23. }
Success #stdin #stdout 0s 15240KB
stdin
1 
acbd
stdout
acdb