Start: Jun, 05, 2019 17:00:00
2019春ACM通识课考试(第三场)
End: Jun, 05, 2019 20:15:00
Time elapsed:
Time remaining:

Problem_ID: E
Result: Accepted
Time: 760ms
Memory: 9524kB
Author: 2018212212028
In contest: 1272

#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);
	}
}