一道pascal编程题,求大师解答。

2024-11-23 08:18:02
推荐回答(1个)
回答1:

假设每次得分所得的分值均为1。程序如下:
var
n:integer;
no:array[1..200] of byte;
tr:array[1..200] of real;
s:string[7];
t1,t2:real;
t1m,t1s,t2m,t2s:byte;
score1,score2:byte;
mm,ss:byte;
i,j:integer;
begin
readln(n);
for i:=1 to n do begin
readln(s);
val(copy(s,1,1),no[i],j);
val(copy(s,3,2),mm,j);
val(copy(s,6,2),ss,j);
tr[i]:=mm+ss/60.0;
end;
t1:=0; t2:=0; score1:=0; score2:=0;
if no[1]=1 then inc(score1) else inc(score2);
for i:=2 to n do begin
if score1>score2 then t1:=t1+tr[i]-tr[i-1];
if score2>score1 then t2:=t2+tr[i]-tr[i-1];
if no[i]=1 then inc(score1) else inc(score2);
end;
if score1>score2 then t1:=t1+48-tr[n];
if score2>score1 then t2:=t2+48-tr[n];
writeln;
t1m:=trunc(t1); t1s:=trunc(frac(t1)*60);
t2m:=trunc(t2); t2s:=trunc(frac(t2)*60);
{writeln(t1m:2,':',t1s:2);
writeln(t2m:2,':',t2s:2); }
if t1m<10 then write('0',t1m:1,':') else write(t1m:2,':');
if t1s<10 then writeln('0',t1s:1) else writeln(t1s:2);
if t2m<10 then write('0',t2m:1,':') else write(t2m:2,':');
if t2s<10 then writeln('0',t2s:1) else writeln(t2s:2);
readln;
end.