farhin_khaled

Random

Sep 16th, 2021
893
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2. #define ll long long int
  3. #define ull unsigned long long int
  4. #define pb push_back
  5. #define mp make_pair
  6. #define in insert
  7. #define f first
  8. #define sc second
  9. #define M 1000000
  10. using namespace std;
  11.  
  12. void combination(string s,int lb,int ub,int len,string st)
  13. {
  14.   string a;
  15.   if(ub==len)
  16.   {
  17.     cout << st << endl;
  18.     a = st;
  19.     swap(a[a.length()-2],a[a.length()-1]);
  20.     cout << a << endl;
  21.     return;
  22.   }
  23.   if(st.length()==0) st+= s[lb];
  24.   else st += s[ub];
  25.   combination(s,lb,ub+1,len,st);
  26.   st.clear();
  27.   combination(s,lb+1,lb+1,len,st);
  28. }
  29.  
  30. int main()
  31. {
  32.   string n = "123",a;
  33.   combination(n,0,0,3,a);
  34.  
  35.   return 0;
  36. }
RAW Paste Data