记录编号 7976 评测结果 AAAAAAAWAA
题目名称 IP网络管理员 最终得分 90
用户昵称 Gravatar打不死的羊 是否通过 未通过
代码语言 Pascal 运行时间 0.008 s
提交时间 2008-11-12 16:29:57 内存使用 0.11 MiB
显示代码纯文本
program networkip;
type
fxz1=array[0..8] of integer;
var
f1,f2:text;
ans1,ans2,max,min,a,b,a1,a2,p:fxz1;
s:string;
n,k,i,l,j:longint;
f:boolean;
procedure zh(s:string;var a:fxz1);
var
code,m,i:integer;
ss:string;
begin
for i:=1 to 3 do
begin
m:=pos('.',s);
ss:=copy(s,1,m-1);
delete(s,1,m);
val(ss,a[i],code);
end;
val(s,a[4],code);
end;
{...................................}
procedure pan(a:fxz1);
var
f:boolean;
i:longint;
begin
f:=true;
for i:=1 to 4 do
if a[i]<max[i] then begin f:=false;break;end;
if f then max:=a;
f:=true;
for i:=1 to 4 do
if a[i]>min[i] then begin f:=false;break;end;
if f then min:=a;
end;
{...................................}
procedure zh2(x:longint;var a:fxz1);
var
i:longint;
begin
for i:=0 to 8 do
a[i]:=0;
a[0]:=8;
while x<>0 do
begin
a[a[0]]:=x mod 2;
dec(a[0]);
x:=x div 2;
end;
a[0]:=8-a[0];
if a[0]=0 then a[0]:=1;
end;
{......................................................}
begin
assign(f1,'networkip.in');
assign(f2,'networkip.out');
reset(f1);rewrite(f2);
readln(f1,n);
for i:=1 to 4 do begin max[i]:=0;min[i]:=255;end;
for i:=1 to n do
begin
readln(f1,s);
zh(s,a);
pan(a);
end;
p[8]:=1;
for i:=7 downto 1 do
p[i]:=2*p[i+1];f:=true;
for i:=1 to 4 do
begin
if max[i]=min[i] then begin ans1[i]:=max[i];ans2[i]:=255;end
                 else begin zh2(max[i],a);zh2(min[i],b);
                            if a[0]>b[0] then l:=a[0] else l:=b[0];
                            j:=1;
                            while (a[j]=b[j])and(j<=8)and(f) do
                            begin
                            a1[j]:=a[j];
                            a2[j]:=1;
                            inc(j);
                            end;
                            if j<=8 then for k:=j to 8 do begin f:=false;a1[k]:=0;a2[k]:=0;end;
                            ans1[i]:=0;ans2[i]:=0;
                            for j:=1 to 8 do
                            begin
                            ans1[i]:=ans1[i]+a1[j]*p[j];
                            ans2[i]:=ans2[i]+a2[j]*p[j];
                            end;
                      end;

end;
for i:=1 to 3 do
write(f2,ans1[i],'.');
writeln(f2,ans1[4]);
for i:=1 to 3 do
write(f2,ans2[i],'.');
writeln(f2,ans2[4]);
close(f1);close(f2);
end.