1
+ /* Hacker Blocks */
2
+ /* Title - Smart Keypad - Advanced */
3
+ /* Created By - Akash Modak */
4
+ /* Date - 14/07/2020 */
5
+
6
+ // Given a long vector of strings, print the strings that contain the strings generated by numeric string str.
7
+
8
+ // string searchIn [] = {
9
+ // "prateek", "sneha", "deepak", "arnav", "shikha", "palak",
10
+ // "utkarsh", "divyam", "vidhi", "sparsh", "akku"
11
+ // };
12
+ // For example, if the input is 26 and the string is coding, then output should be coding since 26 can produce co which is contained in coding.
13
+
14
+ // Input Format
15
+ // A numeric string str
16
+
17
+ // Constraints
18
+ // len(str) < 10
19
+ // No of strings in the vector < 10
20
+
21
+ // Output Format
22
+ // Each matched string from the given vector.
23
+
24
+ // Sample Input
25
+ // 34
26
+ // Sample Output
27
+ // vidhi
28
+ // divyam
29
+ // sneha
30
+ // Explanation
31
+ // 34 will result into combinations :
32
+
33
+ // *dg *eg *fg
34
+ // *dh *eh *fh
35
+ // *di *ei *fi
36
+ // Corresponding strings are output.
37
+
38
+ // vidhi contains dh
39
+ // divyam contains di
40
+ // sneha contains eh
41
+
42
+ #include < iostream>
43
+ #include < string>
44
+ using namespace std ;
45
+ string table[]={" " ," .+@$" ," abc" ," def" ," ghi" ," jkl" ," mno" ," pqrs" ," tuv" ," wxyz" };
46
+ string searchIn [] = {
47
+ " prateek" , " sneha" , " deepak" , " arnav" , " shikha" , " palak" ,
48
+ " utkarsh" , " divyam" , " vidhi" , " sparsh" , " akku"
49
+ };
50
+
51
+ void generate (char *inp,char *out, int i, int j){
52
+ if (inp[i]==' \0 ' ){
53
+ out[j]=' \0 ' ;
54
+ for (int k=0 ;k<11 ;k++){
55
+ size_t found = searchIn[k].find (out);
56
+ if (found!=string::npos)
57
+ cout<<searchIn[k]<<endl;
58
+ }
59
+ return ;
60
+ }
61
+ int key = inp[i]-' 0' ;
62
+ if (key==0 )
63
+ generate (inp,out,i+1 ,j);
64
+ for (int m=0 ;table[key][m]!=' \0 ' ;m++){
65
+ out[j]=table[key][m];
66
+ generate (inp,out,i+1 ,j+1 );
67
+ }
68
+ return ;
69
+ }
70
+
71
+ int main () {
72
+ char a[100000 ],out[100000 ];
73
+ cin>>a;
74
+ generate (a,out,0 ,0 );
75
+ return 0 ;
76
+ }
0 commit comments