forked from 1Alisha/HACKTOBERFEST-22
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HreturnAllCodes.cpp
51 lines (43 loc) · 1.16 KB
/
HreturnAllCodes.cpp
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
#include <iostream>
using namespace std;
#include <string>
using namespace std;
int getCodes(string input, string output[]) {
if(input[0] == '\0'){
output[0] = "";
return 1;
}
int first = input[0] - 48;
char firstChar = first + 'a' - 1;
char secondChar = '\0';
string smallOutput1[500];
string smallOutput2[500];
int size1 = getCodes(input.substr(1), smallOutput1);
int size2 = 0;
if(input[1] != '\0'){
int second = first * 10 + input[1] - 48;
if(second >= 10 && second <= 26){
secondChar = second + 'a' - 1;
size2 = getCodes(input.substr(2), smallOutput2);
}
}
int k = 0;
for(int i = 0; i < size1; i++){
output[k] = firstChar + smallOutput1[i];
k++;
}
for(int i = 0; i < size2; i++){
output[k] = secondChar + smallOutput2[i];
k++;
}
return k;
}
int main(){
string input;
cin >> input;
string output[10000];
int count = getCodes(input, output);
for(int i = 0; i < count && i < 10000; i++)
cout << output[i] << endl;
return 0;
}