
题目:点击打开链接
水题一道,刚开始写了一发模拟,后来发现所谓的10^5是个length……果断加了个大数枚举,过了,今天换了个样式重写了个。
易于推出,两个数之间的最大差值为20.
#include <iostream>
#include <cmath>
#include <iomanip>
#include <fstream>
#include <stdio.h>
#include <string>
using namespace std; const int maxn=100001; int max(int a,int b)
{
if(a>b)
return a;
else
return b;
} class bign
{
public:
int len;
int s[maxn];
}; bign addbignum(bign a,bign b)
{
bign c;
c.len=0;
for(int i=0,g=0;g||i<max(a.len,b.len);i++)
{
int x=g;
if(i<a.len)
x+=a.s[i];
if(i<b.len)
x+=b.s[i];
c.s[c.len++]=x%10;
g=x/10;
}
return c;
} int main()
{
int testcase;
cin>>testcase;
for(int z=1;z<=testcase;z++)
{
int res;
string tmpa,tmpb;
bign a,one;
cin>>tmpa;
a.len=tmpa.size();
one.len=1;
one.s[0]=1; for(int i=0;i<a.len;i++)
{
a.s[i]=tmpa[a.len-i-1]-'0';
} a=addbignum(a,one);
for(int j=0;j<=20;j++)
{
res=0;
for(int i=0;i<a.len;i++)
{
res+=a.s[i];
}
if(res%10==0)
{
for(int p=a.len-1;p>=0;p--)
{
cout<<a.s[p];
}
cout<<endl;
break;
} a=addbignum(a,one);
} }
return 0;
}