描述
Mr. B, Mr. G and Mr. M are now in Warsaw, Poland, for the 2012’s ACM-ICPC World Finals Contest. They’ve decided to take a 5 hours training every day before the contest. Also, they plan to start training at 10:00 each day since the World Final Contest will do so. The scenery in Warsaw is so attractive that Mr. B would always like to take a walk outside for a while after breakfast. However, Mr. B have to go back before training starts, otherwise his teammates will be annoyed. Here is a problem: Mr. B does not have a watch. In order to know the exact time, he has bought a new watch in Warsaw, but all the numbers on that watch are represented in Roman Numerals. Mr. B cannot understand such kind of numbers. Can you translate for him?
B先生、G先生和M先生现在正在波兰华沙参加2012年ACM - ICPC世界决赛。他们决定在比赛前每天进行5小时的训练。此外,他们计划每天10点开始训练,因为世界决赛将会这样做。华沙的风景如此迷人,B先生总是想在早饭后到外面散散步。不过,B先生必须在训练开始前回去,否则他的队友会很恼火。这里有个问题: B先生没有手表。为了知道确切的时间,他在华沙买了一只新表,但那表上的所有数字都用罗马数字表示。先生不能理解这种数字。你能替他翻译吗?
输入
Each test case contains a single line indicating a Roman Numerals that to be translated. All the numbers can be found on clocks. That is, each number in the input represents an integer between 1 and 12. Roman Numerals are expressed by strings consisting of uppercase ‘I’, ‘V’ and ‘X’. See the sample input for further information.
每个测试用例包含一行,指示要翻译的罗马数字。所有的数字都可以在时钟上找到。也就是说,输入中的每个数字表示1到12之间的整数。罗马数字由大写字母“I”、“V”和“X”组成的字符串表示。有关详细信息,请参阅示例输入。
输出
For each test case, display a single line containing a decimal number corresponding to the given Roman Numerals.
对于每个测试用例,显示一行包含对应于给定罗马数字的十进制数。
样例输入
I
II
III
IV
V
VI
VII
VIII
IX
X
XI
XII样例输出
Case 1: 1
Case 2: 2
Case 3: 3
Case 4: 4
Case 5: 5
Case 6: 6
Case 7: 7
Case 8: 8
Case 9: 9
Case 10: 10
Case 11: 11
Case 12: 12
代码如下
#include< stdio.h>
#include< string.h>
int main()
{
char a[100];//定义一个字符数组;
int x,y=1;//这里的y负责输出Case后面的那个数;
while(scanf(“%s”,&a)!=EOF)//然后依次比较这12个罗马数字;
{
if(strcmp(a,”I”)==0)
{
x=1;//这里的x负责罗马数字的翻译,即将罗马数字翻译成阿拉伯数字输出出来;
}
else if(strcmp(a,”II”)==0)
{
x=2;
}
else if(strcmp(a,”III”)==0)
{
x=3;
}
else if(strcmp(a,”IV”)==0)
{
x=4;
}
else if(strcmp(a,”V”)==0)
{
x=5;
}
else if(strcmp(a,”VI”)==0)
{
x=6;
}
else if(strcmp(a,”VII”)==0)
{
x=7;
}
else if(strcmp(a,”VIII”)==0)
{
x=8;
}
else if(strcmp(a,”IX”)==0)
{
x=9;
}
else if(strcmp(a,”X”)==0)
{
x=10;
}
else if(strcmp(a,”XI”)==0)
{
x=11;
}
else
{
x=12;
}
printf(“Case %d: %d\n”,y++,x);//最后输出y++(由于每次输出都要+1,y为第一次的输出);
}
return 0;
}