比赛 NOIP2008集训模拟3 评测结果 AAAAAAAAAA
题目名称 IP网络管理员 最终得分 100
用户昵称 辨机ZN 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2008-11-12 11:18:05
显示代码纯文本
  1. program ex(f1,f2);
  2. type
  3. zn=array [1..1009] of string;
  4. ka=array [0..9] of integer;
  5. la=array [0..4] of string;
  6. var
  7. a:zn; f1,f2:text; s,s2,ym,ip,now:string;
  8. i,j,k,l,p,m,n,ansn:longint; two:ka;
  9. ans1,ans2:la; nows:string;
  10. function zhuanhuan(s:string):string;
  11. var
  12. i,j,k,x,code:integer; s2,s3,s4:string;
  13. begin
  14. val(s,x,code);
  15. s2:='';
  16. while x<>0 do
  17. begin
  18. s2:=s2+char((x mod 2)+48);
  19. x:=x div 2;
  20. end;
  21. l:=length(s2);
  22. s3:='';
  23. for i:=1 to l do s3:=s3+'0';
  24. for i:=1 to l do s3[l-i+1]:=s2[i];
  25. if l<8 then begin
  26. s4:='';
  27. for i:=1 to 8-l do s4:=s4+'0';
  28. s3:=s4+s3;
  29. end;
  30. exit(s3);
  31. end;
  32. function shijinzhi(s:string):string;
  33. var
  34. i,j,k,x:integer; s2:string;
  35. begin
  36. x:=0;
  37. for i:=8 downto 1 do
  38. if s[i]='1' then
  39. begin
  40. x:=x+two[8-i];
  41. end;
  42. str(x,s2);
  43. exit(s2);
  44. end;
  45.  
  46.  
  47.  
  48. begin
  49. assign(f1,'networkip.in'); reset(f1);
  50. assign(f2,'networkip.out'); rewrite(f2);
  51. readln(f1,n);
  52. two[1]:=2; two[0]:=1;
  53. for i:=2 to 8 do two[i]:=two[i-1]*2;
  54. for i:=1 to n do
  55. begin
  56. readln(f1,s);
  57. for k:=1 to 3 do
  58. begin
  59. s2:=copy(s,1,pos('.',s)-1);
  60. s2:=zhuanhuan(s2);
  61. a[i]:=a[i]+s2;
  62. delete(s,1,pos('.',s));
  63. end;
  64. s2:=zhuanhuan(s);
  65. a[i]:=a[i]+s2;
  66. end;
  67. now:=a[1];
  68. for i:=2 to n do
  69. begin
  70. for j:=1 to 32 do
  71. if now[j]<>a[i][j] then break;
  72. now:=copy(now,1,j-1);
  73. end;
  74. ansn:=32-length(now);
  75. for i:=1 to (32-ansn) do ym:=ym+'1';
  76. for i:=1 to ansn do ym:=ym+'0';
  77.  
  78. ip:=now;
  79. while length(ip)<32 do ip:=ip+'0';
  80. for i:=1 to 4 do
  81. begin
  82. nows:=copy(ip,1,8);
  83. delete(ip,1,8);
  84. ans1[i]:=shijinzhi(nows);
  85. end;
  86. for i:=1 to 4 do
  87. begin
  88. nows:=copy(ym,1,8);
  89. delete(ym,1,8);
  90. ans2[i]:=shijinzhi(nows);
  91. end;
  92. for i:=1 to 3 do write(f2,ans1[i],'.'); writeln(f2,ans1[4]);
  93. for i:=1 to 3 do write(f2,ans2[i],'.'); writeln(f2,ans2[4]);
  94. close(f2);
  95. close(f1);
  96. end.
  97.  
  98.  
  99.  
  100.