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:受不了1002!!In Reply To:受不了1002!! Posted by:paulzcy at 2003-11-12 12:24:46 program p1002(input,output); const num:array['0'..'Z']of longint=(0,1,2,3,4,5,6,7,8,9, 0,0,0,0,0,0,0, 2,2,2,3,3,3,4, 4,4,5,5,5,6,6, 6,7,0,7,7,8, 8,8,9,9,9,0); prime=259837; var number:array[0..100050]of longint; times:array[0..100050]of longint; next:array[0..100050]of longint; p:longint; ch:string; n:longint; i,j:longint; l:longint; s,t:longint; ok:boolean; hash:array[0..prime-1]of record number:longint; link:longint; end; function hash_find(num:longint):longint; var p:longint; found:boolean; begin p:=num mod prime; found:=false; while (not found) and (hash[p].number>=0) do if hash[p].number=num then found:=true else p:=(p+1) mod prime; if found then hash_find:=hash[p].link else hash_find:=0; end; procedure hash_insert(num:longint;l:longint); var p:longint; begin p:=num mod prime; while hash[p].number>0 do p:=(p+1) mod prime; hash[p].number:=num; hash[p].link:=l; end; procedure print(num:longint); var p:longint; begin p:=num div 10000; if p<10 then write('00',p) else if p<100 then write('0',p) else write(p); write('-'); p:=num mod 10000; if p<10 then write('000',p) else if p<100 then write('00',p) else if p<1000 then write('0',p) else write(p); end; begin next[0]:=0; number[0]:=-1; l:=0; readln(n); fillchar(hash,sizeof(hash),0); for i:=1 to prime do hash[i].number:=-1; for i:=1 to n do begin p:=0; readln(ch); j:=0; while j<=length(ch) do begin if (ch[j] in['0'..'9']) or (ch[j] in ['A'..'Z']) then p:=p*10+num[ch[j]]; inc(j); end; s:=hash_find(p); if s>0 then inc(times[s]) else begin s:=0; repeat t:=s; s:=next[s]; until (s=0) or (number[s]>p); inc(l); number[l]:=p; times[l]:=1; next[l]:=next[t]; next[t]:=l; hash_insert(p,l); end; end; ok:=true; i:=next[0]; while i>0 do begin if times[i]>1 then begin print(number[i]); writeln(' ',times[i]); ok:=false; end; i:=next[i]; end; if ok then write('No duplicates.'); end. Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator