2015年1月18日星期日

NKPC3-1704 Bowling Ball 保龄球

本来这个是早在百度空间就写了的,然而后来百度空间改版,造成很多文章排版出现问题,之前的URL地址也会失效,另外百度发布文章会有敏感词问题,还有插入代码会很蛋疼,所以现在将此篇文章迁移到Blogger。

Bowling

Time Limit: 2 Sec  Memory Limit: 64 MB


南开大学ACM协会的一个元老毕业后,开了家保龄球馆。他需要为他的保龄球馆的计算机写一个记分的程序。
       一局(GAME)保龄球分为10格,每格里有两次投球机会,如在第一次投球时没能全中,就有需要投第二球。
        每一格可能出现三种情况:
1.失球(MISS)
        无论何种情况,在一格的两次投球时,未能击倒10个瓶,此格的分数为击倒的瓶数。如果一次击球中未击倒一个瓶,则用一个’-’标记。
2.补中(SPARE)
         要一次击倒十个瓶子并非那么容易的!如果在第一次掷球后,你还有一次机会来击倒该格第一球所留下的情致。当第二次投球击倒该格第一球余下的全部瓶子,称为补中,用一个‘/’符号表示。补中的记分是10分加上下一次投球击倒的瓶数。
3.全中(STRIKE)
       当每一格的第一次投球击倒全部竖立的十个瓶时,称为全中,用一个(×)符号表示。全中的记分是10分(击倒的瓶)加该球员下两次投球击倒的瓶数。
       在第十格中情况比较特殊:
(1)如第二次投球未补中,则第十格得分为第九格得分加上第十格所击倒瓶数。
(2)如第二次投球补中,则追加一次投球机会,第十格得分为第九格得他加上10加上追加一次投球击倒瓶数。
(3)如第一球为全中,则追上加二次投球机会,第十格得分为第九格得分加上10加追加二次投球击倒的瓶数。因此从第一格到第十格的两次追加投球,都为全中,则为12个全中,得分为满分300分。
Input
  输入包括多组测试数据,你应当处理到输入结束为止。
  每组输入数据中,都只有一行,包含一局的记分符号,相邻的两个符号之间以一个空格隔开。记分的符号仅包括‘-’(不含引号)、‘/’(不含引号)、’X’(不含引号)及阿拉伯数字1到9。
Output
  对于每组输入数据,输出两行。对于第i组输入数据,输出的第一行为”Case i:”,输出的第二行为10个整数,表示每格的累计得分。相邻的两个得分以一个空格隔开。
Sample Input
X X X X X 5 / 7 1 - - X X X X4 4 3 3 2 2 1 7 7 1 2 - 9 / 2 2 6 3 2 / 1
Sample Output
Case 1:
30 60 90 115 135 152 160 160 190 220
Case
2:8 14 18 26 34 36 48 52 61 72
Source


Description

A patriarch of Nankai University ACM Association operates a bowling alley after graduation. Now, he needs a program to keep the score for the bowling.

There are ten frames in one game. You have two chances to knock down the ten pins in each frame. There are three possible cases for each frame.

1.MISS
If you fail to knock down all of the ten pins during two delivers in a frame, the score you get from this frame will be the number of the pins that you have knocked down. If your deliver knocks down zero pin, your score board will be marked a "-".

2.SPARE
Getting all ten pins down with a single ball is not as easy as it seems! So, if you leave one or more pins standing after your first delivery, you get a second chance to knock all the pins down. This is your "spare" shot. If you knock all remaining pins down on the second shot you have made your spare. A spare is marked on the scoresheet with a "/".And the score you get will be 10 plus the number of pins you knock down during the next delivery.

3. STRIKE
When the bowler knocks down all ten pins during the first delivery in a frame, it is called a strike. Clearly your score goes up by ten, but like a spare, you get a bonus – the number of pins you knock down during your next two deliveries, which will be added to the score. A strike is on the scoresheet with an "X".

Note that the tenth frame is a little different with others.
(1) If you don't knock down the ten pins, the score will be added by the numbers of pins you knock down.
(2) The tenth frame rewards you with a final bonus ball if you convert your spare. And your score will be added by 10 and the number of pins you knock down during your final bonus delivery.
(3) If you make a strike, you will get two bonus balls. The score will be added by 10 and the number of pins you knock down during your final two bonus deliveries.You can thus throw nine strikes in the first nine frames and, if you get another two in the tenth, the bonus ball means the most strikes you can have in one game is twelve. And the full mark is 300.


Input

Input contains several cases. The input is ended up with the end of file (EOF). Each case includes one line which contains several numbers and signs to record a bowling game. The signs are '-', '/' or 'X'. And the numbers range from 1 to 9. The adjacent signs and numbers are separated by one blank.

Output

For each case, please output two lines. The first line for the i-th input case should be "Case i:". The second line should be 10 integers, standing for the 10 accumulative scores of the frames in a bowling game. And each two adjacent integers should be separated by one blank.

Sample Input

X X X X X 5 / 7 1 - - X X X X
4 4 3 3 2 2 1 7 7 1 2 - 9 / 2 2 6 3 2 / 1

Sample Output

Case 1:
30 60 90 115 135 152 160 160 190 220
Case 2:
8 14 18 26 34 36 48 52 61 72

HINT


Source

NKPC3



本来NKPC3比赛时,我一直没有思路,总是想着要
按照回合数划分数组,
没有做出来,就一直搁置着。
现在突然来了灵感,
用(总计)击球次数划分数,
不论是存储,还是处理运算,都比较简单。
这样一来,回合数没有了实际作用,沦为主计算过程(cal(culate))执行次数的计数器。
{详见PASCAL源代码的"~"以及"~~"处}

以下是本人用GCC做的解答: 以下是本人用PASCAL做的解答: 以下是好友Liuhy用PASCAL做的解答: 原帖发布时间:2007年10月05日

没有评论:

发表评论