#include <stdio.h>
#define DEBUG 1
#define TESTCASES 8
int pages;
char *RomanNumbers= "IVXLCDM";
//pattern表示一位(个,十,百,千)上的罗马数字的字母表示模式,采用012表示为了方便跟RomanNumbers的下标关联
char *pattern[10] = {"-1", "0", "00", "000", "01", "1", "10", "100", "1000", "02"};
//count[i]表示代表罗马数字的字母RomanNumbers[i]的统计结果
int count[7];
int main(){
#if DEBUG
int testCase;
for (testCase = 1; testCase <= TESTCASES; testCase++){
char inputFileName[20] = "inputx.txt";
inputFileName[5] = '1' + (testCase - 1);
freopen(inputFileName, "r", stdin);
printf("\n#%d\n", testCase);
#endif
int RomanIndex;
for (RomanIndex = 0; RomanIndex < 7; RomanIndex++)
count[RomanIndex] = 0;
scanf("%d", &pages);
int num;
for (num = 1; num <= pages; num++){
int divisor= 1000;
RomanIndex = 6;
int tempNum = num;
while ( tempNum != 0){
int digit = tempNum / divisor;
if (digit != 0){
int i;
for (i = 0; pattern[digit][i] != '\0'; i++)
count[ RomanIndex + pattern[digit][i] - '0' ]++;
}
tempNum %= divisor;
divisor /= 10;
RomanIndex -= 2;
}
}
for (RomanIndex = 0; RomanIndex < 7; RomanIndex++)
if (count[RomanIndex] != 0)
printf("%c %d\n", RomanNumbers[RomanIndex], count[RomanIndex]);
#if DEBUG
}
#endif
return 0;
}
USACO 2.2 Preface Numbering (模拟)
最新推荐文章于 2022-10-03 22:16:25 发布