-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdualpal.cpp
More file actions
75 lines (65 loc) · 1.25 KB
/
dualpal.cpp
File metadata and controls
75 lines (65 loc) · 1.25 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
ID: dswei191
LANG: C++
TASK: dualpal
*/
#include <iostream>
#include <fstream>
#include <sstream>
#include <algorithm>
using namespace std;
ofstream fout( "dualpal.out");
ifstream fin("dualpal.in");
string decimalTran(int val, int n){
string ret = "";
while(val > 0){
stringstream ss;
int t = val % n;
if(t >= 10){
char strT = 'A' + (t - 10);
ret += strT;
}else{
ret += (t + '0');
}
val = val / n;
}
reverse(ret.begin(), ret.end());
return ret;
}
bool checkPal(string str){
int length = str.length();
for(int i = 0; i < length / 2; i++){
if(str[i] != str[length - i-1]){
return false;
}
}
return true;
}
bool checkDualPal(int val){
int cnt = 0;
for(int i = 2; i <= 10; i++){
string str = decimalTran(val, i);
if(checkPal(str)){
++cnt;
}
if(cnt >= 2){
return true;
}
}
return false;
}
int main(){
int n, s;
fin >> n >> s;
int t = s+1;
while(n--){
while(true){
if(checkDualPal(t)){
fout << t <<endl;
++t;
break;
}
++t;
}
}
}