记录编号 7987 评测结果 AAAAAAAAAA
题目名称 IP网络管理员 最终得分 100
用户昵称 Gravatarbing 是否通过 通过
代码语言 Pascal 运行时间 0.033 s
提交时间 2008-11-12 16:53:15 内存使用 1.33 MiB
显示代码纯文本
program bing;
var
 f1,f2:text;
 n,k:integer;
 st:string;
 s:array[1..1000,1..4] of string;
 s1:array[1..1000] of string;
procedure init;
var
 i,j,x:integer;
begin
 assign(f1,'networkip.in');reset(f1);
 assign(f2,'networkip.out');rewrite(F2);
 readln(f1,n);
 for i:=1 to n do
 begin
 readln(f1,st);
 for j:=1 to 3 do
  begin
  s[i,j]:=copy(st,1,pos('.',st)-1);
  delete(st,1,pos('.',st));
  end;
  s[i,4]:=st;
 end;
 for i:=4 downto 1 do
 begin
 st:=s[1,i];
 for j:=2 to n do
 if s[j,i]<>st then
 begin k:=i;break;end;
 end;
 if n=1 then k:=4;
 for i:=k to 4 do
 for j:=1 to n do
 begin
 st:='';
 val(s[j,i],x);
 repeat
 st:=chr(48+(x mod 2))+st;
 x:=x div 2;
 until x=0;
 s[j,i]:=st;
 while length(s[j,i])<8 do s[j,i]:='0'+s[j,i];
 end;
 for i:=1 to n do
 begin
 s1[i]:='';
 for j:=k to 4 do s1[i]:=s1[i]+s[i,j];
 end;
end;
procedure print(s:string);
var
 i,j,x:integer;
begin
 repeat
 x:=ord(s[1])-48;;
 for i:=2 to 8 do
 x:=x*2+ord(s[i])-48;
 delete(s,1,8);
 if s='' then write(F2,x)
 else write(f2,x,'.');
 until s='';
end;
procedure nb;
var
 i,j,l:integer;
 t:char;
 tt:string;
begin
 for i:=length(s1[1]) downto 1 do
 begin
 t:=s1[1,i];
 for j:=1 to n do
 if s1[j,i]<>t then begin l:=i;break;end;
 end;
 if n=1 then l:=length(s1[1])+1;

 tt:=copy(s1[1],1,l-1);
 for i:=l to length(s1[1]) do
 tt:=tt+'0';
 for j:=1 to k-1 do write(f2,s[1,j],'.');
 print(tt);
 writeln(f2);
 for i:=1 to k-1 do write(f2,'255','.');
 tt:='';
 for i:=1 to l-1 do tt:=tt+'1';
 for i:=l to length(s1[1]) do
 tt:=tt+'0';
 print(tt);
end;
begin
 init;
 nb;
 close(f1);close(F2);
end.