BR8.PAS 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. const
  2. Inp1 = 'inpit1.txt';
  3. Inp2 = 'input2.txt';
  4. Out1 = 'output1.txt';
  5. type
  6. Pty = ^ty;
  7. ty = record
  8. name1 : String[10];
  9. Name2 : String[10];
  10. next : Pty;
  11. end;
  12. var
  13. Root1,Root2 : Pty;
  14. f1,f2 : text;
  15. {==========================================}{P1}
  16. Procedure ReadM(var root : pty;inp : string);
  17. var
  18. Tec,Pred : Pty;
  19. S : string;
  20. I : integer;
  21. begin
  22. Assign(f1,Inp);
  23. Reset(f1);
  24. New(tec);
  25. Readln(f1,S);
  26. I := Pos(' ',S);
  27. if I > 10 Then Begin
  28. Write('Too Long name');
  29. Halt(255);
  30. end;
  31. Tec^.Name1 := Copy(S,1,I-1);
  32. if Length(s)-I > 10 Then begin
  33. Write('Too Long Surname');
  34. Halt(255);
  35. end;
  36. Tec^.Name2 := Copy(S,I+1,Length(S)-I);
  37. Root := Tec;
  38. Root^.next := nil;
  39. Pred := Tec;
  40. While not(Eof(F1)) do begin
  41. New(Tec);
  42. Readln(f1,S);
  43. I := Pos(' ',S);
  44. if I > 10 Then Begin
  45. Write('Too Long name');
  46. Halt(255);
  47. end;
  48. Tec^.Name1 := Copy(S,1,I-1);
  49. if Length(s)-I > 10 Then begin
  50. Write('Too Long Surname');
  51. Halt(255);
  52. end;
  53. Tec^.Name2 := Copy(S,I+1,Length(S)-I);
  54. Pred^.next := Tec;
  55. Pred := Tec;
  56. Tec^.Next := nil;
  57. end;
  58. close(f1);
  59. end;
  60. {==========================================}
  61. {==========================================} {p2}
  62. Procedure OuttoFils(Root : pty;Out : string);
  63. begin
  64. Assign(F2,Out);
  65. ReWrite(f2);
  66. while root<>nil do Begin
  67. WriteLn(f2,Root^.name1,' ',Root^.name2);
  68. root := root^.next;
  69. end;
  70. close(f2);
  71. end;
  72. {==========================================}
  73. Procedure P3(Var Root1,Root2 : pty); {p3}
  74. var
  75. Tec,Sled,Pred : Pty;
  76. begin
  77. Tec := Root2;
  78. While Tec <> Nil do begin
  79. If (Tec^.name1 = Root1^.name1) and (Tec^.name2 = Root1^.name2) Then
  80. begin
  81. Sled := Root1;
  82. Root1 := Root1^.next;
  83. dispose(Sled);
  84. end
  85. else begin
  86. Pred := Root1;
  87. Sled := Root1^.next;
  88. While Sled<> Nil do begin
  89. If (Tec^.name1 = Sled^.name1) and (Tec^.name2 = Sled^.name2) Then
  90. begin
  91. Pred^.next := Sled^.next;
  92. Dispose(Sled);
  93. Sled := Pred^.next;
  94. end
  95. else begin
  96. Pred := Sled;
  97. Sled := Sled^.next;
  98. end;
  99. end;
  100. Tec := Tec^.next;
  101. end;
  102. end;
  103. end;
  104. {==========================================}
  105. begin
  106. ReadM(Root1,inp1);
  107. ReadM(Root2,inp2);
  108. P3(Root1,Root2);
  109. OuttoFils(Root1,Out1);
  110. end.