-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtelephone.cpp
More file actions
41 lines (31 loc) · 809 Bytes
/
telephone.cpp
File metadata and controls
41 lines (31 loc) · 809 Bytes
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
#include <iostream>
#include <string>
#include <unordered_map>
using namespace std;
void telephone(const string & number, int index, string strSoFar, unordered_map<char, string> & myMap) {
if (index == number.length()-1){
cout<<strSoFar<<endl;
return;
}
string digits = myMap[number[index]];
for (int i = 0; i < digits.length(); ++i){
strSoFar.push_back(digits[i]);
telephone(number, index+1, strSoFar, myMap);
strSoFar.pop_back();
}
return;
}
int main(){
unordered_map<char, string> myMap;
myMap['0'] = "0";
myMap['1'] = "1";
myMap['2'] = "ABC";
myMap['3'] = "DEF";
myMap['4'] = "GHI";
myMap['5'] = "JKL";
myMap['6'] = "MNO";
myMap['7'] = "PQRS";
myMap['8'] = "TUV";
myMap['9'] = "WXYZ";
telephone("4087302499", 0, "", myMap);
}