Advertisement
Saleh127

UVA 146 / Next_Permutation

Oct 5th, 2021
823
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int tt; cin>>tt; for(int cs=1;cs<=tt;cs++)
  5. int main()
  6. {
  7.     ios_base::sync_with_stdio(0);
  8.     cin.tie(0);
  9.     cout.tie(0);
  10.  
  11.     string a;
  12.  
  13.     while(cin>>a)
  14.     {
  15.         if(a=="#") break;
  16.  
  17.         ll i=0;
  18.  
  19.         while(next_permutation(a.begin(),a.end()))
  20.         {
  21.             i=1;
  22.             cout<<a<<endl;
  23.             break;
  24.         }
  25.  
  26.         if(i==0) cout<<"No Successor"<<endl;
  27.     }
  28.  
  29.     return 0;
  30. }
  31.  
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement