比赛 |
NOIP2008集训模拟3 |
评测结果 |
AAAAAAAAAW |
题目名称 |
IP网络管理员 |
最终得分 |
90 |
用户昵称 |
E.M.B.E.R |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2008-11-12 09:35:57 |
显示代码纯文本
program EmberAsh;
label 1;
const
cc:array[0..9]of char=('0','1','2','3','4','5','6','7','8','9');
nn:array['0'..'9']of integer=(0,1,2,3,4,5,6,7,8,9);
ttt:array[0..20]of longint=(1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536,131072,262144,524288,1048576);
var
i,j,k,n,m,temp,tt:longint;
a:array[1..100]of longint;
t:array[1..4]of longint;//十进制
ip:array[1..1000,1..4]of integer;//存放ip
ips:array[1..1000]of string;//ip 2进制
head:longint;
s:string;//二进制
tail:longint;
w1:array[1..32]of integer;
ziwangyanma,wangluodizhi:string;
st:string;
ch:char;
fin,fout:text;
procedure tentwo(x:longint);
var
i,j,k,p:longint;
s:string;
begin
p:=0;
while x>0 do
begin
inc(p);
a[p]:=x mod 2;
x:=x div 2;
end;
end;
BEGIN
assign(fin,'networkip.in');reset(fin);
assign(fout,'networkip.out');rewrite(fout);
readln(fin,m);
head:=1;
for i:=1 to m do
begin
tail:=1;
while not(eoln(fin)) do
begin
read(fin,ch);
if ch<>'.' then
st:=st+ch
else
begin
val(st,ip[i,tail]);
st:='';
inc(tail);
end;
end;
val(st,ip[i,tail]);
st:='';
readln(fin);
end;
for i:=1 to m do
for j:=1 to 4 do
begin
for k:=1 to 8 do a[k]:=0;
tentwo(ip[i,j]);
for k:=8 downto 1 do
ips[i]:=ips[i]+cc[a[k]];
end;
//求n
for i:=1 to 32 do
begin
ch:=ips[1,i];
for j:=2 to m do
if ips[j,i]<>ch then
begin
n:=i;
goto 1;
end;
end;
//求n
1:
n:=32-n+1;
for i:=1 to 32-n do
ziwangyanma:=ziwangyanma+'1';
for i:=1 to n do
ziwangyanma:=ziwangyanma+'0';
for i:=1 to 32-n do
wangluodizhi:=wangluodizhi+ips[1,i];
for i:=1 to n do
wangluodizhi:=wangluodizhi+'0';
j:=0;
k:=0;
s:=wangluodizhi;
for i:=8 downto 1 do
begin
j:=j+nn[s[i]]*ttt[k];
inc(k);
end;
write(fout,j);
write(fout,'.');
k:=0;
j:=0;
for i:=16 downto 9 do
begin
j:=j+nn[s[i]]*ttt[k];
inc(k);
end;
write(fout,j);
write(fout,'.');
k:=0;
j:=0;
for i:=24 downto 17 do
begin
j:=j+nn[s[i]]*ttt[k];
inc(k);
end;
write(fout,j);
write(fout,'.');
k:=0;
j:=0;
for i:=32 downto 25 do
begin
j:=j+nn[s[i]]*ttt[k];
inc(k);
end;
write(fout,j);
writeln(fout);
//网络地址
j:=0;
k:=0;
s:=ziwangyanma;
for i:=8 downto 1 do
begin
j:=j+nn[s[i]]*ttt[k];
inc(k);
end;
write(fout,j);
write(fout,'.');
k:=0;
j:=0;
for i:=16 downto 9 do
begin
j:=j+nn[s[i]]*ttt[k];
inc(k);
end;
write(fout,j);
write(fout,'.');
k:=0;
j:=0;
for i:=24 downto 17 do
begin
j:=j+nn[s[i]]*ttt[k];
inc(k);
end;
write(fout,j);
write(fout,'.');
k:=0;
j:=0;
for i:=32 downto 25 do
begin
j:=j+nn[s[i]]*ttt[k];
inc(k);
end;
write(fout,j);
writeln(fout);
//子网掩码
close(fin);close(fout);
END.