Guest User

Untitled

a guest
Dec 27th, 2019
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1. #include<iostream>
  2. #include<cstring>
  3. using namespace std;
  4. char a[][10] = {"", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wx", "yz"};
  5.  string temp;
  6.  
  7. void print(char *s, char *out, int i, int j, int &count){
  8.    if(s[i] == '\0'){
  9.        out[j] = '\0';
  10.        cout<<out<<" ";
  11.        count++;
  12.        return;
  13.  
  14.    }
  15.    int digit = temp[i] - '0';
  16.    for(int k = 0; a[digit][k] != '\0'; k++){
  17.     out[j] = a[digit][k];
  18.     print(s, out , i + 1, j + 1, count);  
  19.    }
  20.        
  21. }
  22.  
  23.  
  24. int main() {
  25.    
  26.     cin>>temp;
  27.     char *s = new char[temp.length() + 1];
  28.     char *p = new char[temp.length() + 1];
  29.     int count = 0;
  30.     print(s, p, 0, 0, count);
  31.     cout<<"\n"<<count<<endl;
  32.     return 0;
  33. }
Add Comment
Please, Sign In to add comment