Skip to content

Instantly share code, notes, and snippets.

@02015678
Created January 18, 2015 15:20
Show Gist options
  • Save 02015678/c02bf9a9d995a08a80b8 to your computer and use it in GitHub Desktop.
Save 02015678/c02bf9a9d995a08a80b8 to your computer and use it in GitHub Desktop.
Liuhy's PASCAL Solution for NKPC3 Bowling Ball
program NK1704;
var
st:array [1..1000] of char;
score:array [0..10] of integer;
i,tt,line:integer;
qq,ch:char;
procedure main;
var
i,j,th:integer;
a:array [1..10,1..2] of integer;
after10:array [1..2] of integer;
begin
th:=0;
i:=0;
while (i<tt) and (th<10) do
begin
inc(i);
case st[i] of
'X':begin inc(th); a[th,1]:=10; a[th,2]:=-1; end;
'1'..'9':begin
inc(th);
inc(i);
case st[i] of
'-':begin
a[th,1]:= ord(st[i-1])-48;
a[th,2]:= 0;
end;
'1'..'9':begin
a[th,1]:=ord(st[i-1])-48;
a[th,2]:=ord(st[i])-48;
end;
'/':begin a[th,1]:=ord(st[i-1])-48; a[th,2]:=10; end;
end;
end;
'-':begin
inc(th);
inc(i);
case st[i] of
'-':begin
a[th,1]:=0;
a[th,2]:=0;
end;
'1'..'9':begin
a[th,1]:=0;
a[th,2]:=ord(st[i])-48;
end;
'/':begin a[th,1]:=0; a[th,2]:=10; end;
end;
end;
end;
end;
j:=0;
if a[10,1] = 10 then
for i:=1 downto 0 do
begin inc(j);
case st[tt-i] of
'-':after10[j]:=0;
'X':after10[j]:=10;
'1'..'9':after10[j]:=ord(st[tt-i])-48;
'/':begin after10[1]:=0; after10[j]:=10; end;
end;
end
else
if a[10,2] = 10 then
begin
after10[2]:=-1;
case st[tt] of
'-':after10[1]:=0;
'X':after10[1]:=10;
'1'..'9':after10[1]:=ord(st[tt])-48;
end;
end
else begin after10[1]:=-1; after10[2]:=-1; end;
//for i:=1 to 10 do
// writeln(i,' ',a[i,1],' ',a[i,2]);
//for i:=1 to 2 do
// writeln('a',' ',i,' ',after10[i]);
//writeln;
fillchar(score,sizeof(score),0);
for i:=1 to 9 do
begin
if (a[i,1] in [0..9]) and (a[i,2] in [0..9]) then
score[i]:= score[i-1] + a[i,1] + a[i,2];
if a[i,2] = 10 then
score[i]:= score[i-1] + 10 + a[i+1,1];
if a[i,1] = 10 then
if a[i+1,2] = 10 then
score[i]:=score[i-1] + 10 + 10
else
if a[i+1,1] = 10 then
if i+2 > 10 then
score[i]:=score[i-1] + 10 + 10 + after10[1]
else score[i]:=score[i-1] + 10 + 10 + a[i+2,1]
else score[i]:=score[i-1]+a[i+1,1]+a[i+1,2]+10;
end;
if a[10,1] = 10 then
score[10]:=score[9]+10+after10[1]+after10[2]
else if a[10,2] = 10 then
score[10]:=score[9]+10+after10[1]
else
score[10]:=score[9]+a[10,1]+a[10,2];
//for i:=1 to 9 do
// write(score[i]:8);
end;
begin
assign(input,'in.txt');
reset(input);
assign(output,'out.txt');
rewrite(output);
line:=0;
while not eof do
begin
tt:=0;
inc(line);
while not eoln do
begin
inc(tt);
read(ch);
while ch = ' ' do read(ch);
st[tt]:=ch;
end;
readln;
main;
writeln('Case ',line,':');
for i:=1 to 9 do
write(score[i],' ');
writeln(score[10]);
end;
close(output);
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment