-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreturn_keypad_string.cpp
More file actions
82 lines (63 loc) · 1.31 KB
/
Copy pathreturn_keypad_string.cpp
File metadata and controls
82 lines (63 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include<iostream>
using namespace std;
string number_string(int n){
if(n==2){
return "abc";
}
else if(n==3){
return "def";
}
else if(n==4){
return "ghi";
}
else if(n==5){
return "jkl";
}
else if(n==6){
return "mno";
}
else if(n==7){
return "pqrs";
}
else if(n==8){
return "tuv";
}
else if(n==9){
return "wxyz";
}
else{
return " ";
}
}
int return_keypad(int number,string *output){
if(number==0){
output[0]="";
return 1;
}
int remainder=number%10;
int new_number=number/10;
string s=number_string(remainder);
int smallpart=return_keypad(new_number,output);
int s_length=s.length();
for(int i=0;i<s_length-1;i++){
for(int j=0;j<smallpart;j++){
output[j+((i+1)*smallpart)]=output[j];
}
}
for(int i=0;i<s.length();i++){
for(int j=0;j<smallpart;j++){
output[j+((i)*smallpart)]=output[j+((i)*smallpart)]+s[i];
}
}
return s_length*smallpart;
}
int main(){
int number;
cin>>number;
string *output=new string[100];
int answer=return_keypad(number,output);
for(int i=0;i<answer;i++){
cout<<output[i]<<endl;
}
cout<<answer<<endl;
}