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

pascal求助啊(HASH)~一直WA。我10w的数据自己搞了个,不会超时。无解/小写也考虑了~~晕倒了啊

Posted by qklxtlx at 2008-07-05 11:28:06 on Problem 1002 and last updated at 2008-07-05 16:28:43
RT。用的是HASH,特征码为前三位
program p1002;
type node=^datatype;
     datatype=record
              num,s:integer;
              next:node;
              end;
var a:array [0..999] of node;
    c:char;s:longint;
    n,i:integer;
    t:node;check:boolean;
procedure push(i,j:integer);
var p,q,t:node;
begin
 if (a[i]=nil) or (a[i]^.num>j) then
 begin
  new(t);t^.num:=j;t^.s:=1;
  t^.next:=a[i];a[i]:=t;
 end
 else
 begin
  p:=a[i];q:=p^.next;
  while (q<>nil) and (q^.num<=j) do
  begin p:=q;q:=p^.next; end;
  if p^.num=j then inc(p^.s) else
  begin
   new(t);t^.num:=j;t^.s:=1;p^.next:=t;t^.next:=q;
  end;
 end;
end;
procedure print(i,j,s:integer);
begin
 if i<10 then write('00',i) else
  if i<100 then write('0',i) else write(i);
 write('-');
 if j<10 then write('000',j) else
  if j<100 then write('00',j) else
   if j<1000 then write('0',j) else write(j);
 writeln(' ',s);
end;
begin{main}
 assign(input,'1002.in');reset(input);
 readln(n);
 for i:=0 to 999 do a[i]:=nil;
 for i:=1 to n do
 begin
  s:=0;
  while not eoln do
  begin
   read(c);
   case c of
    'A','B','C','a','b','c':s:=s*10+2;
    'D','E','F','d','e','f':s:=s*10+3;
    'G','H','I','g','h','i':s:=s*10+4;
    'J','K','L','j','k','l':s:=s*10+5;
    'M','N','O','m','n','o':s:=s*10+6;
    'P','R','S','p','r','s':s:=s*10+7;
    'T','U','V','t','u','v':s:=s*10+8;
    'W','X','Y','w','x','y':s:=s*10+9;
    '0'..'9':s:=s*10+(ord(c)-ord('0'));
   end;
  end;
  push(s div 10000,s mod 10000);
  readln;
 end;
 close(input);check:=false;
 for i:=0 to 999 do
 begin
  t:=a[i];
  while t<>nil do
  begin
   if t^.s>1 then
   begin
    print(i,t^.num,t^.s);check:=true;
   end;
   t:=t^.next;
  end;
 end;
 if not check then writeln('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