比赛 |
NOIP2008集训模拟3 |
评测结果 |
AAAAAAAAAA |
题目名称 |
IP网络管理员 |
最终得分 |
100 |
用户昵称 |
francis |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2008-11-12 09:31:40 |
显示代码纯文本
program networkip;
const
fin='networkip.in';
fou='networkip.out';
var
a:array[1..1000,1..32]of integer;
c,b:array[1..32]of longint;
n1,n2:array[1..4]of longint;
st,s:string;
k,x,y,l,p,q,n,i,j:longint;
f1,f2:text;
function num(st:string):longint;
var
x,l,i:longint;
begin
x:=0;
l:=length(st);
for i:=1 to l do
x:=x*10+ord(st[i])-48;
exit(x);
end;
procedure two(x:longint);
var
y,i,j:longint;
begin
i:=8;
fillchar(b,sizeof(b),0);
repeat
b[i]:=x mod 2;
x:=x div 2;
dec(i);
until x=0;
end;
procedure init;
begin
assign(f1,fin);
assign(f2,fou);
reset(f1); rewrite(f2);
readln(f1,n);
for i:=1 to n do
begin
readln(f1,s);
l:=length(s);
for j:=1 to 4 do
begin
p:=pos('.',s);
if p=0 then p:=l+1;
st:=copy(s,1,p-1);
x:=num(st);
two(x);
for k:=1 to 8 do
a[i,(j-1)*8+k]:=b[k];
s:=copy(s,p+1,l-p);
end;
end;
for i:=1 to 32 do
b[i]:=a[1,i]; x:=32;
end;
procedure main;
begin
for i:=2 to n do
begin
y:=1;
while (y<=32)and(b[y]=a[i,y]) do
inc(y);
if y-1<x then x:=y-1
end;
end;
begin
init;
main;
for i:=x+1 to 32 do b[i]:=0;
for i:=1 to 4 do
begin
j:=1;
while j<=8 do
begin
c[j]:=b[(i-1)*8+j];
inc(j);
end;
for j:=8 downto 1 do
n1[i]:=c[j]*trunc(exp((8-j)*ln(2)))+n1[i];
end;
for i:=1 to x do b[i]:=1;
for i:=1 to 4 do
begin
j:=1;
while j<=8 do
begin
c[j]:=b[(i-1)*8+j];
inc(j);
end;
for j:=8 downto 1 do
n2[i]:=c[j]*trunc(exp((8-j)*ln(2)))+n2[i];
end;
for i:=1 to 3 do
write(f2,n1[i],'.');
writeln(f2,n1[4]);
for i:=1 to 3 do
write(f2,n2[i],'.');
write(f2,n2[4]);
close(f1); close(f2);
end.