暴力枚举。。。
1 202
208
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn=200100;
char str[maxn];
bool ck(char str[])
{
int r=0;
int n=strlen(str);
for(int i=0;i<n;i++)
{
r+=(str[i]-‘0‘)%10;
r=r%10;
}
if(r%10==0) return true;
return false;
}
bool PlusOne(char str[])
{
int c=1;
int n=strlen(str);
for(int i=0;;i++)
{
if(i>=n) str[i]=‘0‘;
int t=str[i]-‘0‘;
if(t+c<10)
{
str[i]++;
c=0;
break;
}
else
{
str[i]=‘0‘+t+c-10;
c=1;
}
}
return true;
}
int main()
{
int T_T;
scanf("%d",&T_T);
while(T_T--)
{
memset(str,0,sizeof(str));
scanf("%s",str);
reverse(str,str+strlen(str));
while(PlusOne(str)) if(ck(str)) break;
reverse(str,str+strlen(str));
printf("%s\n",str);
}
return 0;
}
HDOJ 4608 I-number,布布扣,bubuko.com
原文:http://blog.csdn.net/u012797220/article/details/22430047