Guest User

Untitled

a guest
Jan 25th, 2020
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.38 KB | None | 0 0
  1. #include<iostream>
  2. #include<string>
  3. #include<set>
  4. using namespace std;
  5. char arr[] = {'0', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y','Z'};
  6. set<string> se;
  7. void print(int * a, int n, int pos, string s ){
  8.    
  9.     if(pos > n){
  10.         // cout<<"Ret 1"<<endl;
  11.         return;
  12.     }
  13.        
  14.     if(pos == n-1){
  15.         string newstr = s;
  16.         // cout<<"Ret 2"<<endl;
  17.         if(a[pos]< 27 && a[pos]>=1){
  18.         // {   cout<<"Ret 3"<<endl;
  19.             newstr += arr[a[pos]];
  20.             cout<<newstr<<endl;
  21.             se.insert(newstr);
  22.            
  23.         }
  24.         return;    
  25.     }
  26.    
  27.     if(pos >= n-2){
  28.         // cout<<"Ret 4"<<endl;
  29.        
  30.         if(a[pos] <= 2 && a[pos+1] < 7){
  31.             // cout<<"Ret 5"<<endl;
  32.             string newstr = s;
  33.             int num = a[pos]*10 + a[pos+1];
  34.             newstr += arr[num];
  35.             cout<<newstr<<endl;
  36.             se.insert(newstr);
  37.         }
  38.         string newstr = s;
  39.         //as that . is already computed above
  40.         if(a[pos] == 0 || a[pos+1] == 0){
  41.             // cout<<"Ret 6"<<endl;
  42.             return;
  43.         }
  44.            
  45.         newstr += arr[a[pos]];
  46.         newstr += arr[a[pos+1]];
  47.         // cout<<"Ret 7"<<endl;
  48.         cout<<newstr<<endl;
  49.        
  50.         se.insert(newstr);
  51.         return;
  52.     }
  53.     if(pos < n - 2 && a[pos]<=2 && a[pos+1]<7){
  54.         // cout<<"Ret 8"<<endl;
  55.         string newstr = s;
  56.         int num = a[pos]*10 + a[pos+1];
  57.         newstr += arr[num];
  58.         // cout<<newstr<<endl;
  59.         print(a, n, pos+2, newstr);
  60.        
  61.     }
  62.    
  63.     s += arr[a[pos]];
  64.     // cout<<"Bottom"<<endl;  // cout<<s<<endl;
  65.  
  66.     if(pos == n-1){
  67.         // cout<<"Ret 10"<<endl;
  68.         cout<<s<<endl;
  69.        
  70.         se.insert(s);
  71.         return;
  72.     }
  73.        
  74.    
  75.     print(a, n, pos+1, s);
  76.     return;
  77. }
  78.  
  79. int main(){
  80.     string s;
  81.     cin>>s;
  82.    
  83.     int n = s.length();
  84.     int a[s.length()];
  85.    
  86.     for(int i = 0; i < n; i++){
  87.         a[i] = s[i] - '0';
  88.       //  cout<<a[i]<<endl;
  89.     }
  90.        
  91.     print(a, n, 0, "");
  92.     // Problem : These line below are giving many errors don't know why
  93.     // set <int > :: iterator itr;
  94.     // for (itr = se.begin(); itr != se.end(); ++itr)
  95.     // {
  96.     //     cout  << *itr<<endl;
  97.     // }
  98.     return 0;
  99. }
Add Comment
Please, Sign In to add comment