-
Notifications
You must be signed in to change notification settings - Fork 0
/
1024.cpp
92 lines (87 loc) · 1.17 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
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<queue>
#include<iostream>
#include<sstream>
#include<string>
#include<map>
#include<string.h>
using namespace std;
#undef DEBUG
class Big
{
public:
int a[200];
int b[200];
int len;
void read(char s[])
{
int i;
len=strlen(s);
for(i=0;i<len;i++)
{
a[i]=s[len-i-1]-'0';
}
}
void gen()
{
int i;
for(i=0;i<len;i++)
b[i]=a[len-i-1];
}
bool check()
{
gen();
int i;
for(i=0;i<len;i++)
if(a[i]!=b[i])
return false;
return true;
}
void add()
{
int i;
a[len]=0;
for(i=0;i<len;i++)
a[i]=a[i]+b[i];
for(i=0;i<len;i++)
if(a[i]>=10)
{
a[i]=a[i]%10;
a[i+1]++;
}
if(a[len]!=0)
len++;
}
void print()
{
for(int i=len-1;i>=0;i--)
printf("%d",a[i]);
}
};
int main()
{
freopen("input.in","r",stdin);
freopen("output.out","w",stdout);
char buffer[30];
int k;
scanf("%s%d",buffer,&k);
Big b;
b.read(buffer);
int step=0;
while(step<k)
{
if(b.check())
break;
else
{
b.add();
step++;
}
}
b.print();
printf("\n%d",step);
return 0;
}