POJ 1002(字符串处理)

内容目录

这题就是字符串处理

Program P1002;
Type
   phone=record
         num,s:longint;
         end;
var
   n,i,j,p:Longint;
   b:boolean;
   s:ansistring;
   a:array[0..9999999] of longint;
// f:array[1..100000] of phone;
   ch:array['A'..'Z'] of longint=(2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,-1,7,7,8,8,8,9,9,9,-1);
function isdight(c:char):longint;
var
   i,j,p:longint;
begin
   p:=ord(c);
   if (48<=p) and (p<58) then exit(p-48);
   if (65<=p) and (p<=90) then
   begin
      if ch[c]<>-1 then exit(ch[c]);
   end;
   exit(-1);

end;
function hash:longint;
var
   i,j,p:longint;
begin
   j:=0;
   hash:=0;
   for i:=1 to length(s) do
   begin
      if s[i]='-' then continue;
      p:=isdight(s[i]);
      if (p=-1) or ((p<>-1) and (j=7)) then exit(-1);
      hash:=hash*10+p;
      inc(j);
   end;
   if j<>7 then exit(-1);
end;
procedure pri(p:longint);
var
   i,j:longint;
begin
   b:=true;
   i:=p div 10000;
   j:=p mod 10000;
   if i<100 then write('0');
   if i<10 then write('0');
   write(i,'-');
   if j<1000 then write('0');
   if j<100 then write('0');
   if j<10 then write('0');
   writeln(j,' ',a[p]);
end;
Begin
   b:=false;
   readln(n);
   fillchar(a,sizeof(a),0);
   for i:=1 to n do
   begin
      readln(s);
      p:=hash;
      if p=-1 then continue
      else inc(a[p]);
   end;
   for i:=0 to 9999999 do
      if a[i]>1 then pri(i);
   if not(b) then writeln('No duplicates.');


End.