-
Notifications
You must be signed in to change notification settings - Fork 92
/
Copy pathalphacode.cpp
56 lines (47 loc) · 805 Bytes
/
alphacode.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
52
53
54
55
56
#include <bits/stdc++.h>
using namespace std;
/*
All possible codes that an integer string can generate.
1 = a, 2 = b , 3 = c, ...... 26 = z;
input:
1123
output:
aabc
aaw
alc
kbc
kw
*/
void solve(string &input, string &t, int i)
{
if (i >= input.size())
{
cout << t << endl;
return;
}
if(input[i] == '0')
return;
int a = input[i] - '0';
if (input[i] <= '9')
{
t.push_back((char)(96 + a));
solve(input, t, i + 1);
t.pop_back();
}
if (i + 1 < input.size() && (input[i] == '1' || (input[i] == '2' && input[i + 1] <= '6')))
{
int b = input[i + 1] - '0';
int c = a * 10 + b;
t.push_back((char)(96 + c));
solve(input, t, i + 2);
t.pop_back();
}
}
int main(int argc, char const *argv[])
{
string s;
cin >> s;
string t;
solve(s, t, 0);
return 0;
}