Skip to content

Instantly share code, notes, and snippets.

@02015678
Last active August 29, 2015 14:13
Show Gist options
  • Save 02015678/7b424a43418e2f0a8a63 to your computer and use it in GitHub Desktop.
Save 02015678/7b424a43418e2f0a8a63 to your computer and use it in GitHub Desktop.
PASCAL Solution for NKPC3 Bowling Ball
Const
ch1:set of char=['/','-','X','1'..'9']; {记分的有效符号}
Var
pnt,k,i,j:byte; {(总计)击球次数的指针:p(oi)nt}
ans:integer; {得分:ans(wer)}
a:array[1..11,1..21]OF char; {存储每一次记分字符的数组:a(rray)}
ch:char; {用于读取输入文件的字符变量:ch(ar)}
Function chk(k,pnt:byte):byte; {求(总计)第n次击球击倒的个数:ch(ec)k}
Begin
Case a[k,pnt] OF
'X':chk:=10;
'/':chk:=10-chk(k,pnt-1); {如果补中,个数为10减去上次击球个数}
'-':chk:=0;
'1'..'9':chk:=ord(a[k,pnt])-ord('0');
End;
End;
Procedure cal(k:byte;VAR pnt:byte); {~} {对一个回合进行记分的过程:cal(culate)}
{输入时,pnt为上一回合最后一次击球的(总计)次数}
Var
tmp:byte; {临时变量:t(e)mp}
Begin
inc(pnt); {处理第一次击球}
IF a[k,pnt]='X'
THEN tmp:=10+chk(k,pnt+1)+chk(k,pnt+2)
ELSE {如果没有全中,则这一次回合有下一次击球}
Begin
tmp:=chk(k,pnt); inc(pnt);
IF a[k,pnt]='/'
THEN tmp:=10+chk(k,pnt+1)
ELSE inc(tmp,chk(k,pnt));
End;
inc(ans,tmp);
End;
BEGIN{主程序}
fillchar(a,sizeof(a),'*');{数组初始化}
k:=0;
Repeat {读入每一组数据}
inc(k); pnt:=0;
Repeat
inc(pnt); read(ch);
IF ch IN ch1 THEN a[k,pnt]:=ch
ELSE dec(pnt);
Until eoln(input);
Until eof(input);
IF a[k,1]='*' THEN dec(k); {确定情况(Case)数}
For i:=1 to k Do {计算并输出}
Begin
pnt:=0; ans:=0; writeln('Case ',i,':');
For j:=1 to 10 Do {~~}
Begin
cal(i,pnt); write(ans);
IF j<10 THEN write(' ');
End;
writeln;
End;
END.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment