Guest User

Untitled

a guest
Jan 15th, 2020
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.56 KB | None | 0 0
  1. #include<iostream>
  2. #include<string>
  3.  
  4. using namespace std;
  5.  
  6. char alpha[28] = {'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', '/0'};
  7.  
  8.  
  9. int strToInt(string s){
  10.     int num = 0, copy = 0;
  11.     for(int i = 0; i < s.length(); i++){
  12.         num = s[i] - '0';
  13.         copy = copy*10 + num;
  14.     }
  15.     return copy;
  16. }
  17.  
  18. void pattern(string input, string remain, int least){
  19.     if(input.length() <= 0 || least < 0){
  20.         return ;
  21.     }
  22.     if(input.length()  == 1){
  23.         int a = input[0] - '0';
  24.         if(a <= 0 || a > 26)
  25.             return ;
  26.         cout<<alpha[a]<<endl;;
  27.     }
  28.    
  29.     //printing desired patterns
  30.     string copy;
  31.         for(int i = 0; i <= least ; i++)
  32.              copy += input[i];
  33.         copy += remain;
  34.         cout<<copy<<endl;
  35.    
  36.    
  37.     string dtemp = input[least - 1] + input[least];
  38.     int dnum = strToInt(dtemp);
  39.     if(dnum >= 0 && dnum <= 26){
  40.         string subCopy = alpha[dnum]+ remain;
  41.        // copy += subCopy;
  42.         pattern(input, subCopy, least - 2);  
  43.     }
  44.     // string stemp = ;
  45.     int snum = input[least] - '0';
  46.     if(snum >= 0 && snum <= 26){
  47.         string subCopy = alpha[snum]+ remain;
  48.        // copy += subCopy;
  49.         pattern(input, subCopy, least - 1);
  50.  
  51.     }
  52.    
  53.    
  54.     return;
  55. }
  56.  
  57. int main() {
  58.     int t;
  59.     cin>>t;
  60.     while(t--){
  61.        string input;
  62.        cin>>input;
  63.       // int least = input.length() - 1;
  64.        pattern(input, "", input.length() - 1);
  65.     }
  66.     return 0;
  67. }
Add Comment
Please, Sign In to add comment