Skip to content

Commit ec02b1b

Browse files
authored
Smart Keypad - I Solution Added
1 parent 369c430 commit ec02b1b

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

Hacker Blocks/Smart Keypad - I.cpp

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/* Hacker Blocks */
2+
/* Title - Smart Keypad - I */
3+
/* Created By - Akash Modak */
4+
/* Date - 14/07/2020 */
5+
6+
// You will be given a numeric string S. Print all the possible codes for S.
7+
8+
// Following vector contains the codes corresponding to the digits mapped.
9+
10+
// string table[] = { " ", ".+@$", "abc", "def", "ghi", "jkl" , "mno", "pqrs" , "tuv", "wxyz" };
11+
12+
// For example, string corresponding to 0 is " " and 1 is ".+@$"
13+
14+
// Input Format
15+
// A single string containing numbers only.
16+
17+
// Constraints
18+
// length of string <= 10
19+
20+
// Output Format
21+
// All possible codes one per line in the following order.
22+
23+
// The letter that appears first in the code should come first
24+
25+
// Sample Input
26+
// 12
27+
// Sample Output
28+
// .a
29+
// .b
30+
// .c
31+
// +a
32+
// +b
33+
// +c
34+
// @a
35+
// @b
36+
// @c
37+
// $a
38+
// $b
39+
// $c
40+
// Explanation
41+
// For code 1 the corresponding string is .+@$ and abc corresponds to code 2.
42+
43+
#include<iostream>
44+
using namespace std;
45+
string table[] = { " ", ".+@$", "abc", "def", "ghi", "jkl" , "mno", "pqrs" , "tuv", "wxyz" };
46+
void generate(char *inp,int i,int j,char *out){
47+
if(inp[i]=='\0'){
48+
out[j]='\0';
49+
cout<<out<<endl;
50+
return;
51+
}
52+
53+
int key = inp[i] - '0';
54+
// if(key==0)
55+
// generate(inp,i+1,j,out);
56+
for(int k=0;table[key][k]!='\0';k++){
57+
out[j]=table[key][k];
58+
generate(inp,i+1,j+1,out);
59+
}
60+
return;
61+
}
62+
int main() {
63+
64+
char inp[100],out[1000];
65+
cin>>inp;
66+
generate(inp,0,0,out);
67+
return 0;
68+
}

0 commit comments

Comments
 (0)