记录编号 7914 评测结果 AAAAAAAAAA
题目名称 IP网络管理员 最终得分 100
用户昵称 Gravatar王瑞祥K 是否通过 通过
代码语言 Pascal 运行时间 0.009 s
提交时间 2008-11-12 15:00:10 内存使用 0.12 MiB
显示代码纯文本
program networkip(input,output);
const
 n2:array[1..8]of integer=(1,2,4,8,16,32,64,128);
var
 st,zh:string;
 ip,zw,new:array[1..32]of integer;
 bh,t:array[1..8]of integer;
 nip:array[1..4]of integer;
 i,j,k,l,p,tot,m,n,code:longint;
begin
 assign(input,'networkip.in');assign(output,'networkip.out');
 reset(input);rewrite(output);
 readln(m);
 for i:=1 to m do begin
  readln(st);
  for j:=1 to 3 do begin
   p:=pos('.',st); zh:=copy(st,1,p-1); val(zh,nip[j],code); delete(st,1,p);
  end;
  val(st,nip[4],code);

  for j:=1 to 4 do begin
   for k:=1 to 8 do t[k]:=0;
   if nip[j]=0 then for k:=1 to 8 do t[k]:=0
   else begin
    tot:=0;
    while nip[j]<>0 do begin
     inc(tot); t[tot]:=nip[j] mod 2; nip[j]:=nip[j] div 2;
    end;
   end;
   l:=9;
   for k:=(j-1)*8+1 to j*8 do begin dec(l); new[k]:=t[l];end;
  end;

  if i=1 then begin for j:=1 to 32 do ip[j]:=new[j];n:=32;end
  else begin
   j:=0;
   while (ip[j+1]=new[j+1]) and (j<n) do inc(j);
   n:=j;
  end;
 end;
 n:=32-n;

 for i:=32-n+1 to 32 do begin ip[i]:=0;zw[i]:=0;end;
 for i:=1 to 32-n do zw[i]:=1;

 for i:=1 to 4 do begin
  tot:=0; k:=9;
  for j:=(i-1)*8+1 to i*8 do begin
   dec(k);
   tot:=tot+ip[j]*n2[k];
  end;
  write(tot);if i<>4 then write('.');
 end;
 writeln;
 for i:=1 to 4 do begin
  tot:=0; k:=9;
  for j:=(i-1)*8+1 to i*8 do begin
   dec(k);
   tot:=tot+zw[j]*n2[k];
  end;
  write(tot);if i<>4 then write('.');
 end;
 close(input);close(output);
end.