比赛 |
NOIP2008集训模拟3 |
评测结果 |
AAAAAAAAAA |
题目名称 |
IP网络管理员 |
最终得分 |
100 |
用户昵称 |
辨机ZN |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2008-11-12 11:18:05 |
显示代码纯文本
- program ex(f1,f2);
- type
- zn=array [1..1009] of string;
- ka=array [0..9] of integer;
- la=array [0..4] of string;
- var
- a:zn; f1,f2:text; s,s2,ym,ip,now:string;
- i,j,k,l,p,m,n,ansn:longint; two:ka;
- ans1,ans2:la; nows:string;
- function zhuanhuan(s:string):string;
- var
- i,j,k,x,code:integer; s2,s3,s4:string;
- begin
- val(s,x,code);
- s2:='';
- while x<>0 do
- begin
- s2:=s2+char((x mod 2)+48);
- x:=x div 2;
- end;
- l:=length(s2);
- s3:='';
- for i:=1 to l do s3:=s3+'0';
- for i:=1 to l do s3[l-i+1]:=s2[i];
- if l<8 then begin
- s4:='';
- for i:=1 to 8-l do s4:=s4+'0';
- s3:=s4+s3;
- end;
- exit(s3);
- end;
- function shijinzhi(s:string):string;
- var
- i,j,k,x:integer; s2:string;
- begin
- x:=0;
- for i:=8 downto 1 do
- if s[i]='1' then
- begin
- x:=x+two[8-i];
- end;
- str(x,s2);
- exit(s2);
- end;
-
-
-
- begin
- assign(f1,'networkip.in'); reset(f1);
- assign(f2,'networkip.out'); rewrite(f2);
- readln(f1,n);
- two[1]:=2; two[0]:=1;
- for i:=2 to 8 do two[i]:=two[i-1]*2;
- for i:=1 to n do
- begin
- readln(f1,s);
- for k:=1 to 3 do
- begin
- s2:=copy(s,1,pos('.',s)-1);
- s2:=zhuanhuan(s2);
- a[i]:=a[i]+s2;
- delete(s,1,pos('.',s));
- end;
- s2:=zhuanhuan(s);
- a[i]:=a[i]+s2;
- end;
- now:=a[1];
- for i:=2 to n do
- begin
- for j:=1 to 32 do
- if now[j]<>a[i][j] then break;
- now:=copy(now,1,j-1);
- end;
- ansn:=32-length(now);
- for i:=1 to (32-ansn) do ym:=ym+'1';
- for i:=1 to ansn do ym:=ym+'0';
-
- ip:=now;
- while length(ip)<32 do ip:=ip+'0';
- for i:=1 to 4 do
- begin
- nows:=copy(ip,1,8);
- delete(ip,1,8);
- ans1[i]:=shijinzhi(nows);
- end;
- for i:=1 to 4 do
- begin
- nows:=copy(ym,1,8);
- delete(ym,1,8);
- ans2[i]:=shijinzhi(nows);
- 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(f2);
- close(f1);
- end.
-
-
-
-