比赛 NOIP2008集训模拟3 评测结果 AAAAAAAAAW
题目名称 IP网络管理员 最终得分 90
用户昵称 苏轼 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2008-11-12 09:15:45
显示代码纯文本
program cch(input,output);
var
 i,n,k,j,q,k1,tmp,ans,key,code,ans1:integer;
 a:array[1..1000,1..4] of integer;
 s,s1:string;
 flag:boolean;
begin
 assign(input,'networkip.in');
 assign(output,'networkip.out');
 reset(input);
 rewrite(output);
 readln(n);
 for i:=1 to n do
  begin
   readln(s);
   s:=s+'.';
   for k:=1 to 4 do
    begin
     s1:=copy(s,1,pos('.',s)-1);
     val(s1,a[i,k],code);
     delete(s,1,pos('.',s));
    end;
  end;

 for i:=1 to 4 do
  begin
   flag:=true; tmp:=a[1,i];
   for j:=2 to n do
    if tmp<>a[j,i] then
     begin
      flag:=false;
      break;
     end;
   if not flag then
    begin
     key:=i;
     break;
    end;
  end;

 for k:=8 downto 1 do
  begin
   tmp:=a[1,key] shr (k-1) and 1;
   for j:=2 to n do
    begin
     k1:=a[j,key] shr (k-1) and 1;
     if (tmp=0)and(k1=1)or(tmp=1)and(k1=0) then
      begin
       ans:=a[1,key] or (1 shl k-1);
       ans:=ans xor (1 shl k-1);
       for i:=1 to key-1 do
        write(a[1,i],'.');
       write(ans);
       for i:=key+1 to 4 do
        write('.',0);
       writeln;
       for i:=1 to key-1 do
        write(255,'.');
       ans1:=0;
       for i:=8 downto k+1 do
        begin
         tmp:=1;
         for q:=1 to i-1 do tmp:=tmp*2;
         ans1:=ans1+tmp;
        end;
       write(ans1);
       for i:=key+1 to 4 do
        write('.',0);
       close(input); close(output);
       halt;
      end;
    end;
  end;
end.