记录编号 |
8003 |
评测结果 |
AAAAAAAAAA |
题目名称 |
IP网络管理员 |
最终得分 |
100 |
用户昵称 |
maxiem |
是否通过 |
通过 |
代码语言 |
Pascal |
运行时间 |
0.007 s |
提交时间 |
2008-11-12 17:38:20 |
内存使用 |
0.11 MiB |
显示代码纯文本
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;
var
cs:string;
j,k,p:integer;
begin
assign (input,'networkip.in');
reset (input);
readln (m);
readln (s);s:=s+'.';cs:=s;
for j:=1 to 4 do begin
p:=pos('.',s);
if length(copy(s,1,p-1))<4 then for k:=1 to 3-length(copy(s,1,p-1)) do insert('0',cs,(j-1)*3+j);
delete (s,1,p);
end;
max:=cs;min:=cs;
for i:=2 to m do begin
readln (s);s:=s+'.';cs:=s;
for j:=1 to 4 do begin
p:=pos('.',s);
if length(copy(s,1,p-1))<4 then for k:=1 to 3-length(copy(s,1,p-1)) do insert('0',cs,(j-1)*3+j);
delete (s,1,p);
end;
if cs>max then max:=cs;
if cs<min then min:=cs;
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;
flag:boolean;
begin
bi:=4;bj:=0;flag:=false;
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;
flag:=true;
break;
end;
if flag then break;
end;
for i:=1 to bi do for j:=1 to 8 do mask[i,j]:=1;
for j:=1 to bj do mask[bi+1,j]:=1;
for i:=1 to bj do if bipmax[bi+1,i]=0 then dec(bj) else break;
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.