分析:大整数相加,数组要开大一点,不能只开20位或者更小,开小了会导致测试点6、8错误
#include <iostream>
#include<cstring>
#include<vector>
#include<stdio.h>
#include<queue>
#include<math.h>
#include<stack>
#include<algorithm>
#include<map>
#include<set>
#define MAX 99999999
using namespace std;
typedef long long ll;
int a[100001];
int b[100001];
int ju(int x[],int len)
{
for(int i = 0;i<len;i++)
if(x[i] != x[len-i-1])
return 0;
return 1;
}
int main()
{
int k;
string s;
cin>>s>>k;
int len = s.size();
for(int i = 0;i<len;i++){
a[i] = s[i] - '0';
b[i] = s[len - i - 1] - '0';
}
if(ju(a,len) == 1){
for(int i = 0;i<len;i++)
cout<<a[i];
cout<<endl;
cout<<0;
return 0;
}
int step = 0;
while(step<k)
{
step++;
for(int i = 0;i<len;i++)
{
a[i] += b[i];
if(a[i]>=10)
{
a[i+1] += a[i]/10;
a[i] %= 10;
}
}
if(a[len]!=0) len++;
if(ju(a,len) == 1){
for(int i = 0;i<len;i++)
cout<<a[i];
cout<<endl;
cout<<step;
return 0;
}
for(int i = 0;i<len;i++)
b[i] = a[len-i-1];
}
for(int i = len-1;i>=0;i--)
cout<<a[i];
cout<<endl;
cout<<k;
return 0;
}