Result: Accepted
Time: 760ms
Memory: 9524kB
#include<algorithm>
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
#define ll long long
struct node
{
int x;
int sum;
}p[1000000];
bool cmp(node x,node y)
{
if(x.sum==y.sum)
{
return x.x<y.x;
}
return x.sum<y.sum;
}
int main ()
{
for (int i = 0; i < 1000000; i++)
{
p[i].x=i;
p[i].sum=0;
int t=p[i].x;
for (int j= 0; ; j++)
{
p[i].sum+=t%10;
if(t%10==0&&t/10==0)break;
t/=10;
}
}
sort(p,p+1000000,cmp);
for (int i = 0; i < 1000000; i++)
{
printf("%06d\n",p[i].x);
}
}