记录编号 7892 评测结果 AAAAAAAAAA
题目名称 IP网络管理员 最终得分 100
用户昵称 Gravatarzhai 是否通过 通过
代码语言 Pascal 运行时间 0.034 s
提交时间 2008-11-12 11:41:33 内存使用 0.36 MiB
显示代码纯文本
program network;
  const
    max=1000;
  type
    sz=array[1..max]of string;
  var
    f1,f2:text;
    n,lx:integer;
    sa,ansa,ansb:string;
    a:sz;
    procedure ini;
      var
        i: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,a[i]);
          a[i]:=a[i]+'.';
        end;
        close(f1);
        sa:='';
        lx:=0;
        ansa:='';ansb:='';
      end;
    procedure zh(s1:string;var s2:string);
      var
        i,j,x,code:integer;
        s,sx:string;
      begin
        s:='';
        sx:='';
        val(s1,x,code);
        j:=0;
        repeat
          i:=x mod 2;
          s:=s+chr(i+48);
          x:=x div 2;
          inc(j);
        until x=0;
        for i:=1 to j do
        sx:=sx+s[j-i+1];
        for i:=1 to 8-j do s2:=s2+'0';
        s2:=s2+sx;
      end;
    procedure pan(s2:string);
      var
        i:integer;
        f:boolean;
        s:string;
      begin
        i:=1;
        s:='';
        f:=true;
        while (i<=lx)and(f)do
          if s2[i]<>sa[i] then f:=false
          else inc(i);
        s:=copy(sa,1,i-1);
        sa:=s;
      end;
    procedure zhao;
      var
        i,k,l,j:integer;
        s,s1,s2:string;
      begin
        s:=a[1];
        for k:=1 to 4 do begin
          l:=pos('.',s);
          s1:=copy(s,1,l-1);
          zh(s1,sa);
          delete(s,1,l);
        end;
        for i:=2 to n do begin
          s:=a[i];
          s2:='';
          for k:=1 to 4 do begin
            l:=pos('.',s);
            s1:=copy(s,1,l-1);
            zh(s1,s2);
            delete(s,1,l);
          end;
          lx:=length(sa);
          pan(s2);
        end;
        l:=length(sa);
        for i:=1 to l do ansa:=ansa+'1';
        ansb:=ansb+sa;
        for i:=1 to (32-l)do begin
          ansa:=ansa+'0';
          ansb:=ansb+'0';
        end;
      end;
    procedure zhuan2(var ans:string);
      var
        i,j,l,d,k,x:integer;
        s,s1:string;
      begin
        s:=ans;
        s1:='';
        ans:='';
        for i:=1 to 4 do begin
          s1:=copy(s,1,8);
          delete(s,1,8);
          d:=0;
          for j:=1 to 8 do begin
            x:=1;
            if s1[j]='1' then begin
              for k:=8-j downto 1 do x:=x*2;
              d:=d+x;
            end;
          end;
          str(d,s1);
          ans:=ans+s1;
          ans:=ans+'.';
        end;
        l:=length(ans);
        delete(ans,l,1);
      end;
  begin
    ini;
    zhao;
    zhuan2(ansa);
    zhuan2(ansb);
    writeln(f2,ansb);
    writeln(f2,ansa);
    close(f2);
  end.