比赛 |
NOIP2008集训模拟3 |
评测结果 |
AAWWWWWWWA |
题目名称 |
IP网络管理员 |
最终得分 |
30 |
用户昵称 |
maxiem |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2008-11-12 11:27:25 |
显示代码纯文本
program networkip;
var
dn,dm,ipmax,ipmin:array [1..4] of byte;
network,mask,bipmax,bipmin:array [1..4,1..8] of 0..1;
s,max,min:string;
code,p,m,i:integer;
procedure init;
begin
assign (input,'networkip.in');
reset (input);
readln (m);
readln (s);s:=s+'.';
max:=s;min:=s;
for i:=2 to m do begin
readln (s);s:=s+'.';
if s>max then max:=s;
if s<min then min:=s;
end;
for i:=1 to 4 do begin
p:=pos('.',max);
val(copy(max,1,p-1),ipmax[i],code);
delete(max,1,p);
end;
for i:=1 to 4 do begin
p:=pos('.',min);
val(copy(min,1,p-1),ipmin[i],code);
delete(min,1,p);
end;
close (input);
end;
procedure binary;
var i,j:integer;
begin
fillchar (bipmax,sizeof(bipmax),0);
fillchar (bipmin,sizeof(bipmin),0);
for i:=1 to 4 do begin
j:=9;
while ipmax[i]<>0 do begin
dec(j);
bipmax[i,j]:=ipmax[i] mod 2;
ipmax[i]:=ipmax[i] div 2;
end;
j:=9;
while ipmin[i]<>0 do begin
dec(j);
bipmin[i,j]:=ipmin[i] mod 2;
ipmin[i]:=ipmin[i] div 2;
end;
end;
end;
procedure build;
var i,j,bi,bj:integer;
begin
bi:=4;bj:=0;
for i:=1 to 4 do begin
for j:=1 to 8 do if bipmax[i,j]<>bipmin[i,j] then begin
bi:=i-1;bj:=j-1;
break;
end;
end;
for i:=1 to bi do for j:=1 to 8 do mask[i,j]:=1;
for i:=bi+1 to 4 do for j:=1 to bj do mask[i,j]:=1;
fillchar (network,sizeof(network),0);
for i:=1 to bi do for j:=1 to 8 do network[i,j]:=bipmin[i,j];
for i:=bi+1 to 4 do for j:=1 to bj do network[i,j]:=bipmin[i,j];
end;
procedure decimal;
var i,j:integer;
begin
fillchar (dn,sizeof(dn),0);
fillchar (dm,sizeof(dm),0);
for i:=1 to 4 do for j:=1 to 8 do dn[i]:=dn[i]+network[i,j] shl (8-j);
for i:=1 to 4 do for j:=1 to 8 do dm[i]:=dm[i]+mask[i,j] shl (8-j);
end;
procedure print;
begin
assign (output,'networkip.out');
rewrite (output);
write (dn[1]);
for i:=2 to 4 do write ('.',dn[i]);
writeln;
write (dm[1]);
for i:=2 to 4 do write ('.',dm[i]);
writeln;
close (output);
end;
begin
init;
binary;
build;
decimal;
print;
end.