-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1024.cpp
More file actions
55 lines (54 loc) · 861 Bytes
/
1024.cpp
File metadata and controls
55 lines (54 loc) · 861 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
bool ispalin(string a){
for(int i=0;i<a.size()/2;i++){
if(a[i] != a[a.size()-i-1])
return false;
}
return true;
}
string sum(string a, string b){
int flag1 = 0,tt=0;
string ssum;
for(int i=a.size()-1;i>=0;i--){
tt = (a[i]-'0')+(b[i]-'0')+flag1;
if(tt>=10){
flag1 = 1;
tt = tt-10;
}else
flag1=0;
ssum.push_back(tt+'0');
}
if(flag1==1)
ssum.push_back(1+'0');
reverse(ssum.begin(),ssum.end());
return ssum;
}
int main(){
string n,m,s="";
int k,t=0;
bool flag=false;
cin>>n>>k;
m=n;
while(!ispalin(n)&&t<k){
t++;
reverse(m.begin(),m.end());
s = sum(n,m);
if(ispalin(s)){
flag = true;
cout<<s<<endl;
cout<<t<<endl;
break;
}
n = s;
m = n;
}
if(!flag){
cout<<n<<endl;
cout<<t<<endl;
}
system("pause");
return 0;
}