比赛 NOIP2008集训模拟3 评测结果 AAAAAAAAAA
题目名称 IP网络管理员 最终得分 100
用户昵称 thegy 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2008-11-12 10:26:27
显示代码纯文本
program networkip;
type
  node=record
         b:array[1..32]of longint;
       end;
var
  fin,fout:text;
  n,i,p,j,num:longint;
  a:array[1..1000]of node;
  ans1,ans2:array[1..32]of longint;
  c:char;
  t,min:longint;
procedure make(x,y,z,w:longint);
var
  pp:longint;
begin
  for pp:=y to z do a[x].b[pp]:=0;
  pp:=z;
  while w<>0 do begin
    a[x].b[pp]:=w mod 2;
    w:=w div 2;
    dec(pp);
  end;
end;
function bj(x,y:longint):longint;
var
  ii:longint;
begin
  for ii:=1 to 32 do
    if a[x].b[ii]<>a[y].b[ii] then break;
  bj:=ii;
end;
function outit(x1,x2,x3,x4,x5,x6,x7,x8:longint):longint;
var
  tt:longint;
begin
  tt:=0;
  if x8=1 then tt:=tt+1;
  if x7=1 then tt:=tt+2;
  if x6=1 then tt:=tt+4;
  if x5=1 then tt:=tt+8;
  if x4=1 then tt:=tt+16;
  if x3=1 then tt:=tt+32;
  if x2=1 then tt:=tt+64;
  if x1=1 then tt:=tt+128;
  outit:=tt;
end;
begin
  assign(fin,'networkip.in'); reset(fin);
  assign(fout,'networkip.out'); rewrite(fout);
  read(fin,n);
  t:=0;
  p:=1;
  for i:=1 to n do begin
    readln(fin);
    while not(eoln(fin)) do begin
      read(fin,c);
      if c='.' then begin
        make(i,8*(p-1)+1,8*p,t);
        inc(p);
        t:=0;
      end else t:=t*10+ord(c)-48;
    end;
    make(i,25,32,t);
    t:=0;
    p:=1;
  end;
  min:=33;
  for i:=1 to n-1 do
    for j:=i+1 to n do begin
      p:=bj(i,j);
      if p<min then min:=p;
    end;
  for i:=1 to min-1 do ans1[i]:=a[1].b[i];
  for i:=min to 32 do ans1[i]:=0;
  for i:=1 to min-1 do ans2[i]:=1;
  for i:=min to 32 do ans2[i]:=0;
  num:=outit(ans1[1],ans1[2],ans1[3],ans1[4],ans1[5],ans1[6],ans1[7],ans1[8]);
  write(fout,num,'.');
  num:=outit(ans1[9],ans1[10],ans1[11],ans1[12],ans1[13],ans1[14],ans1[15],ans1[16]);
  write(fout,num,'.');
  num:=outit(ans1[17],ans1[18],ans1[19],ans1[20],ans1[21],ans1[22],ans1[23],ans1[24]);
  write(fout,num,'.');
  num:=outit(ans1[25],ans1[26],ans1[27],ans1[28],ans1[29],ans1[30],ans1[31],ans1[32]);
  writeln(fout,num);
  num:=outit(ans2[1],ans2[2],ans2[3],ans2[4],ans2[5],ans2[6],ans2[7],ans2[8]);
  write(fout,num,'.');
  num:=outit(ans2[9],ans2[10],ans2[11],ans2[12],ans2[13],ans2[14],ans2[15],ans2[16]);
  write(fout,num,'.');
  num:=outit(ans2[17],ans2[18],ans2[19],ans2[20],ans2[21],ans2[22],ans2[23],ans2[24]);
  write(fout,num,'.');
  num:=outit(ans2[25],ans2[26],ans2[27],ans2[28],ans2[29],ans2[30],ans2[31],ans2[32]);
  writeln(fout,num);
  close(fin);
  close(fout);
end.