-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathisSymm.cpp
More file actions
58 lines (57 loc) · 1008 Bytes
/
isSymm.cpp
File metadata and controls
58 lines (57 loc) · 1008 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <iostream>
#include <string>
#include <vector>
#include <unordered_map>
using namespace std;
bool isPalind(string& str){
if(str.length() == 0){
return true;
}
int i = 0, j = str.length()-1;
while(i < j){
if(str.at(i) != str.at(j)){
return false;
}
i++;
j--;
}
return true;
}
void helper(vector<string>& result, string& path, unordered_map<char, char>& map, int len){
if(len == 0){
if(isPalind(path)){
result.push_back(path);
}
return;
}
for(char c = '0'; c <= '9'; c++){
char mc = map[c];
if(mc == 'x'){
continue;
}
path.push_back(mc);
helper(result, path, map, len-1);
path.pop_back();
}
}
int main(void){
unordered_map<char, char> map;
map['0'] = '0';
map['1'] = '1';
map['2'] = '5';
map['3'] = 'x';
map['4'] = 'x';
map['5'] = '2';
map['6'] = '9';
map['7'] = 'x';
map['8'] = '8';
map['9'] = '6';
vector<string> result;
string src;
int n = 3;
helper(result, src, map, n);
for(string str : result){
cout<<str<<endl;
}
return 0;
}