Advertisement
Guest User

Untitled

a guest
Dec 1st, 2015
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.60 KB | None | 0 0
  1.  
  2. function answer: boolean;
  3. var
  4. s: string;
  5. correct: boolean;
  6. begin
  7. correct := false;
  8. repeat
  9. readln(s);
  10. if (s = 'Да') or (s = 'Нет') then
  11. correct := true
  12. else
  13. write('Введите пожалуйста "Да" или "Нет": ');
  14. until correct;
  15. if s = 'Да' then
  16. answer := true
  17. else
  18. answer := false;
  19. end;
  20.  
  21. function InFile(name: string): string;
  22. var
  23. correct: boolean;
  24. begin
  25. correct := false;
  26. repeat
  27. writeln('Введите имя файла ,в котором хранятся исходные файлы:');
  28. readln(name);
  29. if FileExists(name) then
  30. correct := true
  31. else
  32. begin
  33. writeln('Неправильное имя файла. Повторите, пожалуйста ввод.');
  34. writeln;
  35. end;
  36. until correct;
  37. writeln;
  38. result := name;
  39. end;
  40.  
  41. procedure OutFile(var OutName: string; name: string);
  42. var
  43. correct: boolean;
  44. Writefile: TextFile;
  45. begin
  46. correct := false;
  47. repeat
  48. writeln('Введите имя файла, в котором необходимо разместить результат работы программы.');
  49. readln(OutName);
  50. if FileExists(OutName) and (name <> OutName) then
  51. begin
  52. assign(WriteFile, OutName);
  53. reset(WriteFile);
  54. if seekeof(WriteFile) then
  55. correct := true
  56. else
  57. if correct = false then
  58. begin
  59. writeln('Этот файл содержит данные. Вы хотите очистить его и записать туда результат работы программы?');
  60. if answer then
  61. correct := true;
  62. end;
  63. close(WriteFile);
  64. end
  65. else
  66. if (copy(OutName, length(OutName) - 3, 4) = '.txt') and (name <> OutName) then
  67. begin
  68. writeln('Файл с таким именем не существует. Вы хотите его создать ?');
  69. if answer then
  70. correct := true;
  71. end
  72. else
  73. writeln('Некорректное имя файла, повторите пожалуйста вход.');
  74. writeln;
  75. until correct;
  76. end;
  77.  
  78. function Solution (name: string; Str_Array:array of string) : string;
  79.  
  80. var
  81. Input_File: text;
  82. line, space, buffer: string;
  83. //Str_Array: array of string;
  84. i, j, space_position: integer;
  85. begin
  86. assign(Input_File, name);
  87. reset(Input_File);
  88. while not eof(Input_File) do
  89. begin
  90. readln(Input_File, line);
  91. begin
  92. line := line + ' ';
  93. space := '';
  94. j := 1;
  95. for i := 1 to length(line) do
  96. if line[i] <> ' ' then
  97. space := space + line[i]
  98. else
  99. begin
  100. setlength(Str_Array, j);
  101. Str_Array[j - 1] := space;
  102. space := '';
  103. inc(j);
  104. end;
  105. space_position := j;
  106. j := 0;
  107. while j < space_position - 2 do
  108. begin
  109. buffer := Str_Array[j];
  110. Str_Array[j] := Str_Array[j + 1];
  111. Str_Array[j + 1] := buffer;
  112. j := j + 2;
  113. end;
  114. for j := 0 to space_position - 2 do
  115. write(Str_Array[j], ' ');
  116. end;
  117. end;
  118. close(Input_File);
  119. end;
  120.  
  121. procedure OutResult(OutName: string);
  122. var
  123. WriteFile: TextFile;
  124. begin
  125. assign(WriteFile, OutName);
  126. rewrite(WriteFile);
  127. writeln(WriteFile);
  128. writeln;
  129. close(WriteFile);
  130. readln;
  131. end;
  132.  
  133. procedure user_interface;
  134. begin
  135. writeln(' ---------------------------------------------------');
  136. writeln(' ¦ УСЛОВИЕ ЗАДАЧИ: ¦');
  137. writeln(' ¦ В заданном предложении поменять местами слова, ¦');
  138. writeln(' ¦ стоящие на четных местах со словами, ¦');
  139. writeln(' ¦ стоящими на нечетных местах. ¦');
  140. writeln(' ---------------------------------------------------');
  141. writeln;
  142. end;
  143.  
  144. var
  145. name: string;
  146. OutName: string;
  147. Str_Array:array of string;
  148.  
  149. begin
  150. user_interface;
  151. name := InFile(Name);
  152. OutFile(outName, Name);
  153. writeln('Резаультат работы программы: ' );
  154. solution(name,Str_Array);
  155. outresult(OutName);
  156. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement