枚举秒过。
/*
ID:szwjcch971
TASK:preface
LANG:C++
*/
#include "stdio.h"
#include "string.h"
char alphabet[8]="IVXLCDM";
int main(){
int i,j,n,k;
int total[7];
FILE *fin=fopen("preface.in","r");
FILE *fout=fopen("preface.out","w");
fscanf(fin,"%d",&n);
memset(total,0,sizeof(total));
for(i=1;i<=n;i++){
j=i;
k=j/1000;
j%=1000;
total[6]+=k;
k=j/100;
j%=100;
switch(k){
case 1:total[4]+=1;break;
case 2:total[4]+=2;break;
case 3:total[4]+=3;break;
case 4:total[4]+=1;total[5]+=1;break;
case 5:total[5]+=1;break;
case 6:total[4]+=1;total[5]+=1;break;
case 7:total[4]+=2;total[5]+=1;break;
case 8:total[4]+=3;total[5]+=1;break;
case 9:total[4]+=1;total[6]+=1;break;
default:break;
}
k=j/10;
j%=10;
switch(k){
case 1:total[2]+=1;break;
case 2:total[2]+=2;break;
case 3:total[2]+=3;break;
case 4:total[2]+=1;total[3]+=1;break;
case 5:total[3]+=1;break;
case 6:total[2]+=1;total[3]+=1;break;
case 7:total[2]+=2;total[3]+=1;break;
case 8:total[2]+=3;total[3]+=1;break;
case 9:total[2]+=1;total[4]+=1;break;
default:break;
}
k=j;
switch(k){
case 1:total[0]+=1;break;
case 2:total[0]+=2;break;
case 3:total[0]+=3;break;
case 4:total[0]+=1;total[1]+=1;break;
case 5:total[1]+=1;break;
case 6:total[0]+=1;total[1]+=1;break;
case 7:total[0]+=2;total[1]+=1;break;
case 8:total[0]+=3;total[1]+=1;break;
case 9:total[0]+=1;total[2]+=1;break;
default:break;
}
}
for(i=0;i<=6;i++){
if(total[i])fprintf(fout,"%c %d\n",alphabet[i],total[i]);
}
return 0;
}