Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:我的这个程序超时了 因为有一个repeat until false;In Reply To:肉眼看不出有没有这种数据,你认为有,应该是测试过了,告诉我你测试的程序 Posted by:hawk at 2005-07-17 16:25:48 const fn1 = ''; fn2 = ''; maxn = 1000; type tnode = record name: string; last: integer; end; var a: array[1 .. maxn] of tnode; j1, j2, len, testdata, test, n, i, j, k: integer; st1, st: string; flag: array[1 .. maxn] of boolean; function find: integer; var i: integer; begin for i := 1 to len do if a[i].name = st then begin find := i; exit; end; find := 0; end; procedure readst; var ch: char; begin st := ''; read(ch); while ch <> ' ' do begin st := st + ch; read(ch); end; end; procedure show(i: integer); begin if (i = 0) or (not flag[i]) then exit; flag[i] := false; show(a[i].last); writeln(a[i].name); end; begin assign(input, fn1); reset(input); assign(output, fn2); rewrite(output); readln(testdata); for test := 1 to testdata do begin writeln('Scenario #', test, ':'); len := 0; readln(n); for i := 1 to n - 1 do begin readst; j1 := find; if j1 = 0 then begin len := len + 1; a[len].name := st; j1 := len; end; readln(st); j2 := find; if j2 = 0 then begin len := len + 1; a[len].name := st; j2 := len; end; a[j2].last := j1; end; for i := 1 to n do flag[i] := true; for i := 1 to n do for j := 1 to n do if (i <> j) and (a[i].last = a[j].last) then repeat until false; for i := 1 to n do if flag[i] then show(i); writeln; end; close(output); close(input); end. Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator