-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathA1019.cpp
More file actions
37 lines (33 loc) · 815 Bytes
/
Copy pathA1019.cpp
File metadata and controls
37 lines (33 loc) · 815 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
#include <iostream>
#include <cstring>
#define MAXLEN 35
using namespace std;
int convert(int dst[], int src, int base);
bool isPalin(int dst[], int len);
int main()
{
int n, b, len, dst[MAXLEN];
cin >> n >> b;
len = convert(dst, n, b);
printf(isPalin(dst, len) ? "Yes\n" : "No\n");
for (int i = len - 1; i >= 0; i--) printf((i == 0) ? "%d" : "%d ", dst[i]);
return 0;
}
// dst's number should be output reversely, from (len - 1) to 0
// returnee is the length of dst
int convert(int dst[], int src, int base)
{
int cnt = 0;
do {
dst[cnt++] = src % base;
src /= base;
} while (src > 0);
return cnt;
}
bool isPalin(int dst[], int len)
{
for (int i = 0; i <= len / 2; i++)
if (dst[i] != dst[len-1-i])
return false;
return true;
}