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: 874ms
Memory: 13436kB
Author: 2018212212048
In contest: 1272

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
struct num{
	char N[6];
	int digitroot;
}a[1000020];

bool CMP(const num &x,const num &y){
	if(x.digitroot==y.digitroot){
		if(strcmp(x.N,y.N)<0){
			return true;
		}
		else return false;
	}
	return x.digitroot<y.digitroot;
}

int cal_digitroot(int n){
	int sum=0;
	while(n){
		sum+=n%10;
		n/=10;
	}
	return sum;
}

void init(){
	for(int i=0;i<=999999;i++){
		a[i].digitroot=cal_digitroot(i);
		a[i].N[0]=char(i/100000+'0');
		a[i].N[1]=char((i%100000)/10000+'0');
		a[i].N[2]=char((i%10000)/1000+'0');
		a[i].N[3]=char((i%1000)/100+'0');
		a[i].N[4]=char((i%100)/10+'0');
		a[i].N[5]=char(i%10+'0');
	}
}

int main(){
	init();
	sort(a,a+1+999999,CMP);	
	for(int i=0;i<=999999;i++){
		printf("%s\n",a[i].N);
	}
}