HDU链接 : http://acm.hdu.edu.cn/showproblem.php?pid=1128
POJ链接 : http://poj.org/problem?id=1316
对于每个正整数n,定义运算方式d(n)为:n+n的各位数字,得到新的数
要求我们找到不存在于d(n)里的数
比如1~10内,1+1=2,2+2=4,4+4=8,3+3=6,5+5=10,那么1,3,5,7,9就不在d(n)的运算结果内,输出1,3,5,7,9
先在HDU做的,后来发现POJ也有这题,坑爹的是改了上限,WA了两次,我的法克
#include <cstdio>
using namespace std;
bool ans[1000001]; //POJ将数据改为1w
int main()
{
for(int i=1;i<=1000000;i++)
{
int t1=i,t2=i;
while(t2)
{
t1+=t2%10;
t2/=10;
}
if(t1<=1000000) ans[t1]=1;
}
for(int i=1;i<1000001;i++)
if(!ans[i]) printf("%d\n",i);
return 0;
}