-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPalindromic_number.cpp
57 lines (54 loc) · 1001 Bytes
/
Palindromic_number.cpp
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
#include <iostream>
struct node
{
int date;
struct node *next;
};
int main()
{
long long n, b;
std::cin >> n >> b;
node *h1 = new node;
node *h2 = new node;
h1->next = NULL, h2->next = NULL;
node *h3 = h2;
while (n > 0)
{
int temp = n % b;
n = n / b;
node *p = new node;
node *q = new node;
p->date = temp;
q->date = temp;
p->next = h1->next;
h1->next = p;
h3->next = q;
q->next = NULL;
h3 = q;
}
h3 = h1->next;
h2 = h2->next;
while (h2 != NULL)
{
if (h2->date != h3->date)
break;
h2 = h2->next;
h3 = h3->next;
}
if (h2 != NULL)
{
std::cout << "No" << std::endl;
}
else
{
std::cout << "Yes" << std::endl;
}
h1 = h1->next;
while (h1->next != NULL)
{
std::cout << h1->date << " ";
h1 = h1->next;
}
std::cout << h1->date;
return 0;
}