-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathA1024.cpp
44 lines (43 loc) · 836 Bytes
/
A1024.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
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
string add(string s)
{
string r = s;
reverse(s.begin(),s.end());
int rr = 0;
string ans;
for(int i = r.size()-1; i >= 0; i--){
ans.push_back((r[i]+s[i]-'0'*2+rr)%10+'0');
rr = (r[i]+s[i]-'0'*2)/10;
}
if(rr){
ans.push_back(rr+'0');
}
reverse(ans.begin(),ans.end());
return ans;
}
bool is(string s) {
int i = 0;
int j = s.size()-1;
for(;i<=j;i++,j--){
if(s[i]!=s[j]) return false;
}
return true;
}
int main()
{
string s;
int n;
cin >> s >> n;
for(int i = 0; i < n; i++){
if(is(s)) {
cout << s << endl << i << endl;
return 0;
}
s = add(s);
}
cout << s << endl << n << endl;
}