-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathleet17.cpp
More file actions
47 lines (44 loc) · 1.02 KB
/
Copy pathleet17.cpp
File metadata and controls
47 lines (44 loc) · 1.02 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
#include <vector>
#include <iostream>
using namespace std ;
class Solution {
vector<string>letters ;
char *buf ;
vector<string> res ;
string input ;
public:
Solution(){
string let[] = {"abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"} ;
letters = vector<string>(let, let+8) ;
}
void tryy(int i){
if(i==input.size()){
res.push_back(string(buf)) ;
cout << string(buf) << endl ;
return ;
}
for(int j=0; j<letters[input[i]-'2'].size() ;j++){
cout << j << endl ;
buf[i] = letters[input[i]-'2'][j] ;
tryy(i+1) ;
}
}
vector<string> letterCombinations(string digits) {
res.clear() ;
if(digits.size()==0)
return res ;
buf = new char[digits.size()] ;
input = digits ;
tryy(0) ;
return res ;
}
};
int main(){
Solution sl ;
while(1){
string x ;
cin >> x ;
sl.letterCombinations(x) ;
}
sl.letterCombinations("2") ;
}