| ||||||||||
| 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 | |||||||||
我是新手,各位大虾帮忙看看为什么会超时,用pascal做的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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator