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做的

Posted by tclizeyong at 2009-10-05 19:21:01 on Problem 1002
var q,n,i,j:longint;
    a:string;
    b:Array[1..100000]of string;
    c:array[1..100000]of integer;
procedure qsort(l,r:longint);
var mid,aa:string;
    i,j,t:longint;
begin
  i:=l;j:=r;mid:=b[(l+r)div 2];
  repeat
    while b[i]<mid do i:=i+1;
    while b[j]>mid do j:=j-1;
    if i<=j then begin
                   aa:=b[i];t:=c[i];
                   b[i]:=b[j];c[i]:=c[j];
                   b[j]:=aa;c[j]:=t;
                   i:=i+1;j:=j-1;
                 end;
  until i>j;
  if l<j then qsort(l,j);
  if i<r then qsort(i,r);
end;
begin
  readln(n);
  for i:=1 to n do
    begin
      readln(a);
      for j:=1 to length(a) do
        begin
          if a[j]<>'-' then begin
                              if (a[j]>='0')and(a[j]<='9') then
                                                             b[i]:=b[i]+a[j]
                                  else
                                    case a[j] of
                                    'A','B','C':b[i]:=b[i]+'2';
                                    'D','E','F':b[i]:=b[i]+'3';
                                    'G','H','I':b[i]:=b[i]+'4';
                                    'J','K','L':b[i]:=b[i]+'5';
                                    'M','N','O':b[i]:=b[i]+'6';
                                    'P','R','S':b[i]:=b[i]+'7';
                                    'T','U','V':b[i]:=b[i]+'8';
                                    'W','X','Y':b[i]:=b[i]+'9';
                                    end;
                              end;
        end;
    end;
  for i:=1 to n do
    begin
    c[i]:=1;
    b[i]:=copy(b[i],1,3)+'-'+copy(b[i],4,4);
    end;
  for i:=1 to n-1 do
    if b[i]<>'' then begin
                       for j:=i+1 to n do
                         if b[i]=b[j] then begin
                                             c[i]:=c[i]+1;
                                             b[j]:='';
                                           end;
                    end;
  q:=0;
  for i:=1 to n do
    if (c[i]>1)and(b[i]<>'') then begin q:=q+1;b[q]:=b[i];c[q]:=c[i] end;
  if q=0 then writeln('No duplicates.')
         else begin qsort(1,q);
  for i:=1 to q do
    writeln(b[i],' ',c[i]);end;
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