-
Notifications
You must be signed in to change notification settings - Fork 0
/
1024.cpp
105 lines (95 loc) · 1.74 KB
/
1024.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
//
// main.cpp
// test
//
// Created by 李寻欢 on 2019/10/1.
// Copyright © 2019 李寻欢. All rights reserved.
//
#include <stdio.h>
#include <iostream>
#include <string>
#include <map>
#include <cmath>
#include <algorithm>
#include <stack>
#include <vector>
#include <queue>
#include <unordered_map>
#include <string.h>
#include <set>
using namespace std;
struct bign {
int d[1000];
int len;
bign(){
memset(d, 0, sizeof(d));
len = 0;
}
};
bign change(char c[]){
int len = strlen(c);
bign a;
for (int i=0; i<len; i++) {
a.d[i] = c[len-i-1] - '0' ;
a.len++;
}
return a;
}
bign add(bign a,bign b){
int carry = 0;
int index = 0;
bign c;
for (int i=0; i<a.len; i++) {
int temp = a.d[i] + b.d[i] + carry;
c.d[index++] = temp % 10;
carry = temp / 10;
c.len++;
}
if (carry != 0) {
c.d[index++] = carry;
c.len++;
}
return c;
}
bign Reverse(bign a){
bign b;
b.len = a.len;
for (int i=0; i<a.len; i++) {
b.d[i] = a.d[a.len-1-i];
}
return b;
}
bool istrue(bign a){
for (int i=0; i<a.len/2; i++) {
if (a.d[i] != a.d[a.len-i-1]) {
return false;
}
}
return true;
}
void show(bign a){
for (int i=a.len-1; i>=0; i--) {
printf("%d",a.d[i]);
}
printf("\n");
}
int main(){
int k;
char n[1000];
scanf("%s%d",n,&k);
bign a = change(n);
int count = 0;
while (count < k) {
if (istrue(a)) {
show(a);
printf("%d",count);
return 0;
}else{
count++;
bign b = Reverse(a);
a = add(a, b);
}
}
show(a);
printf("%d",count);
}