Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

受不了1002!!

Posted by paulzcy at 2003-11-12 12:24:46 on Problem 1002
谁能检查下面的程序为什么WA!!!
我从网上下载了原考试的测试数据已经全过了!!!!
为什么!!!!!!!!!
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;
  if i mod 1000=0 then writeln(i);
  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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator