#include<iostream>
#include<string>
#include<cstring>
using namespace std;
void add(char a[],char b[],char back[])
{
int i,j,k,up,x,y,z,l;
char *c;
if (strlen(a)>strlen(b)) l=strlen(a)+2; else l=strlen(b)+2;
c=(char *) malloc(l*sizeof(char));
i=strlen(a)-1;
j=strlen(b)-1;
k=0;up=0;
while(i>=0||j>=0)
{
if(i<0) x='0'; else x=a[i];
if(j<0) y='0'; else y=b[j];
z=x-'0'+y-'0';
if(up) z+=1;
if(z>9) {up=1;z%=10;} else up=0;
c[k++]=z+'0';
i--;j--;
}
if(up) c[k++]='1';
i=0;
c[k]='\0';
for(k-=1;k>=0;k--)
back[i++]=c[k];
back[i]='\0';
}
int res(char s[])
{
int len=strlen(s),d=0,i;
for(i=0;i<len;i++)
{
d+=s[i]-'0';
d%=10;
}
return d;
}
int main()
{
int T,i,j;
cin>>T;
while(T--)
{char s[200086]={'\0'},s1[200086]={'\0'},s2[200086]={'\0'},s3[200086]={'\0'};
cin>>s;
int len=strlen(s);
int d=res(s);
if(d==0)
{
s1[0]=10-(s[len-1]-'0')+'0';
add(s,s1,s2);
d=res(s2);
if(d==0){
cout<<s2<<endl;continue;
}
s1[0]=10-d+'0';
add(s2,s1,s3);
cout<<s3<<endl;
continue;
}
else
{
if(d>s[len-1]-'0')
{
s1[0]=10-d+'0';
add(s,s1,s2);
cout<<s2<<endl;
continue;
}
else{
s1[0]=10-(s[len-1]-'0')+'0';
add(s,s1,s2);
d=res(s2);
if(d==0){
cout<<s2<<endl;continue;
}
s1[0]=10-d+'0';
add(s2,s1,s3);
cout<<s3<<endl;
continue;
}
}
s1[0]=d+'0';
add(s,s1,s2);
cout<<s2<<endl;
}
return 0;
}
hdu4608
最新推荐文章于 2022-08-29 19:51:09 发布