Guest User

Untitled

a guest
Jan 28th, 2020
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.37 KB | None | 0 0
  1. #include <iostream>
  2. #include<string>
  3. #include<bits/stdc++.h>
  4. using namespace std;
  5. char kp[][10] = {"", "", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
  6. string searchIn [] = {
  7.             "prateek", "sneha", "deepak", "arnav", "shikha", "palak",
  8.             "utkarsh", "divyam", "vidhi", "sparsh", "akku"
  9.     };
  10.  
  11.  
  12. void printKeypadString(char *in, char *out, int i, int j)
  13. {
  14.     if(in[i] == '\0')
  15.     {
  16.         out[j] = '\0';
  17.        
  18.        //converting char array to string
  19.         int i;
  20.         string s = "";
  21.         for (i = 0; i < out[i] != '\0'; i++)
  22.               s = s + out[i];
  23.              
  24.         //finding if the string is present as a substring
  25.         for( i = 10; i >= 0; i--)
  26.         {
  27.             // *****************here I am getting no output why????????
  28.               size_t found = searchIn[i].find(s);
  29.                if (found != string::npos) {
  30.                    cout << searchIn[i]<<endl;
  31.                }
  32.                
  33.         }
  34.         return;
  35.     }
  36.  
  37.     int digit = in[i] - '0';
  38.     // cout<<digit<<endl;
  39.     for(int k = 0; kp[digit][k] != '\0'; k++){
  40.       //   cout<<kp[digit][k]<<endl;
  41.         out[j] = kp[digit][k];
  42.         printKeypadString(in, out, i+1, j+1);
  43.     }
  44.     return;  
  45. }
  46.  
  47. int main() {
  48.    
  49.     char a[10], b[10];
  50.     cin>>a;
  51.     printKeypadString(a, b, 0, 0);
  52.     return 0;
  53. }
Add Comment
Please, Sign In to add comment