Vanilla_Fury

zakaz 10_12_2020

Dec 13th, 2020
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.36 KB | None | 0 0
  1. program zakaz_10_12_2020;
  2.  
  3. uses
  4. System.SysUtils;
  5.  
  6. type
  7. TAnswer = Array [0..1] of String;
  8.  
  9. function GetInput() : String;
  10. var
  11. StrInput: String;
  12. IsCorrect, HasOnlySpacesOrEmpty: Boolean;
  13. i: Integer;
  14.  
  15. begin
  16. writeln('Введите строку:');
  17. repeat
  18. IsCorrect := true;
  19. readln(StrInput);
  20. i := 1;
  21.  
  22. HasOnlySpacesOrEmpty := True;
  23. while ((i <= Length(StrInput)) and HasOnlySpacesOrEmpty) do
  24. begin
  25. if (StrInput[i] <> ' ') then
  26. HasOnlySpacesOrEmpty := false;
  27. Inc(i);
  28. end;
  29.  
  30.  
  31. if (HasOnlySpacesOrEmpty) then
  32. begin
  33. writeln('Строка пустая. Повторите попытку:');
  34. IsCorrect := false;
  35. end;
  36. until IsCorrect;
  37.  
  38. GetInput := StrInput;
  39. end;
  40.  
  41. function SearchForFirstWord(StrInput: String) : String;
  42. var
  43. StrWord: String;
  44. ChChar: Char;
  45. i: Integer;
  46. WasNotSpace, FirstWordNotFound: Boolean;
  47.  
  48. begin
  49. StrWord := '';
  50. WasNotSpace := false;
  51. FirstWordNotFound := true;
  52.  
  53. i := 1;
  54. while ((i <= Length(StrInput)) and FirstWordNotFound) do
  55. begin
  56. ChChar := StrInput[i];
  57. if ((ChChar = ' ') or (i = Length(StrInput))) then
  58. begin
  59. if WasNotSpace then
  60. FirstWordNotFound := false;
  61. end
  62. else
  63. begin
  64. StrWord := StrWord + ChChar;
  65. WasNotSpace := true;
  66. end;
  67. Inc(i);
  68. end;
  69.  
  70. Result := StrWord;
  71. end;
  72.  
  73. function SearchForLastWord(StrInput: String) : String;
  74. var
  75. StrWord: String;
  76. ChChar: Char;
  77. i: Integer;
  78. WasNotSpace, LastWordNotFound: Boolean;
  79.  
  80. begin
  81. StrWord := '';
  82. WasNotSpace := false;
  83. LastWordNotFound := true;
  84.  
  85. i := Length(StrInput);
  86. while ((i > 0) and LastWordNotFound) do
  87. begin
  88. ChChar := StrInput[i];
  89. if ((ChChar = ' ') or (i = 1)) then
  90. begin
  91. if WasNotSpace then
  92. LastWordNotFound := false;
  93. end
  94. else
  95. begin
  96. StrWord := ChChar + StrWord;
  97. WasNotSpace := true;
  98. end;
  99. Dec(i);
  100. end;
  101.  
  102. Result := StrWord;
  103. end;
  104.  
  105. function FindConsonatsInWord(StrFirstWord: String) : String;
  106. const
  107. StrConsonats = 'QWRZTPSDFGHKLXCVBNMЙЦКНГШЩЗХФВПРЛДЖЧМТБ';
  108.  
  109. var
  110. i, j, z: Integer;
  111. StrConsonatsInFirstWord: String;
  112. LetterIsAlreadyInString: Boolean;
  113.  
  114. begin
  115. StrConsonatsInFirstWord := '';
  116.  
  117. for i := 1 to Length(StrFirstWord) do
  118. for j := 1 to Length(StrConsonats) do
  119. if (UpperCase(StrFirstWord[i]) = StrConsonats[j]) then
  120. begin
  121. LetterIsAlreadyInString := false;
  122. z := 1;
  123. while ((z <= Length(StrConsonatsInFirstWord)) and not LetterIsAlreadyInString) do
  124. begin
  125. if (StrConsonats[j] = StrConsonatsInFirstWord[z]) then
  126. LetterIsAlreadyInString := True;
  127. Inc(z);
  128. end;
  129. if (not LetterIsAlreadyInString) then
  130. StrConsonatsInFirstWord := StrConsonatsInFirstWord + StrConsonats[j];
  131. end;
  132.  
  133. Result := StrConsonatsInFirstWord;
  134. end;
  135.  
  136. procedure Part1OfTask(var ArrStrAnswer: TAnswer; SWord, StrConsonatsInFirstWord, StrLastWord: String);
  137. var
  138. ConsonatsInWord: String;
  139. ConsonatsEquel, OneLetterEquels: Boolean;
  140. i, j: Integer;
  141.  
  142. begin
  143. if (UpperCase(SWord) <> UpperCase(StrLastWord)) then
  144. begin
  145. ConsonatsInWord := FindConsonatsInWord(SWord);
  146.  
  147. ConsonatsEquel := true;
  148.  
  149. i := 1;
  150. while ((i <= Length(StrConsonatsInFirstWord)) and ConsonatsEquel) do
  151. begin
  152. j := 1;
  153. OneLetterEquels := false;
  154. while ((j <= Length(ConsonatsInWord)) and ConsonatsEquel and not OneLetterEquels) do
  155. begin
  156. if (StrConsonatsInFirstWord[i] = ConsonatsInWord[j]) then
  157. OneLetterEquels := true;
  158. Inc(j);
  159. end;
  160. if not OneLetterEquels then
  161. ConsonatsEquel := false;
  162.  
  163. Inc(i);
  164. end;
  165.  
  166. i := 1;
  167. while ((i <= Length(ConsonatsInWord)) and ConsonatsEquel) do
  168. begin
  169. j := 1;
  170. OneLetterEquels := false;
  171. while ((j <= Length(StrConsonatsInFirstWord)) and ConsonatsEquel and not OneLetterEquels) do
  172. begin
  173. if (ConsonatsInWord[i] = StrConsonatsInFirstWord[j]) then
  174. OneLetterEquels := true;
  175. Inc(j);
  176. end;
  177. if not OneLetterEquels then
  178. ConsonatsEquel := false;
  179.  
  180. Inc(i);
  181. end;
  182.  
  183. if (ConsonatsEquel) then
  184. ArrStrAnswer[0] := ArrStrAnswer[0] + SWord + ' ';
  185.  
  186. end;
  187. end;
  188.  
  189. procedure Part2OfTask(var ArrStrAnswer: TAnswer; SWord, StrLastWord: String; var StrVocalsWhichAlreadyWereInString: String);
  190. const
  191. Vocals = 'EUIOAJYУЕЫАОЭЯИЮЁ';
  192. var
  193. i, j, k:Integer;
  194. VocalIsAlreadyInString, VocalFound: Boolean;
  195. StrWordOutput: String;
  196.  
  197. begin
  198. StrWordOutput := '';
  199. if (UpperCase(SWord) <> UpperCase(StrLastWord)) then
  200. begin
  201. for i := 1 to Length(SWord) do
  202. begin
  203. VocalFound := false;
  204. j := 1;
  205. while ((j <= Length(Vocals)) and not VocalFound) do
  206. begin
  207. if (UpperCase(SWord[i]) = Vocals[j]) then
  208. begin
  209. VocalFound := true;
  210. VocalIsAlreadyInString := false;
  211. k := 1;
  212. while ((k <= Length(StrVocalsWhichAlreadyWereInString)) and not VocalIsAlreadyInString) do
  213. begin
  214. if (UpperCase(SWord[i]) = StrVocalsWhichAlreadyWereInString[k]) then
  215. VocalIsAlreadyInString := true;
  216. Inc(k);
  217. end;
  218.  
  219. if not VocalIsAlreadyInString then
  220. begin
  221. StrVocalsWhichAlreadyWereInString := StrVocalsWhichAlreadyWereInString + Vocals[j];
  222. StrWordOutput := StrWordOutput + SWord[i];
  223. end;
  224. end;
  225.  
  226. Inc(j);
  227. end;
  228.  
  229. if not VocalFound then
  230. StrWordOutput := StrWordOutput + SWord[i];
  231. end;
  232. ArrStrAnswer[1] := ArrStrAnswer[1] + StrWordOutput + ' ';
  233. end;
  234. end;
  235.  
  236. procedure DecideWhatToDoWithFoundWord(var ArrStrAnswer: TAnswer; SWord, StrConsonatsInFirstWord, StrLastWord: String; var StrVocalsWhichAlreadyWereInString: String);
  237.  
  238.  
  239. begin
  240. Part1OfTask(ArrStrAnswer, SWord, StrConsonatsInFirstWord, StrLastWord);
  241. Part2OfTask(ArrStrAnswer, SWord, StrLastWord, StrVocalsWhichAlreadyWereInString);
  242. end;
  243.  
  244. function ComputeAnswer(SInput, StrFirstWord, StrConsonatsInFirstWord, StrLastWord: String) : TAnswer;
  245. var
  246. SWord, StrVocalsWhichAlreadyWereInString: String;
  247. ChChar: Char;
  248. i: Integer;
  249. ArrStrAnswer: TAnswer;
  250.  
  251. begin
  252. ArrStrAnswer[0] := '';
  253. ArrStrAnswer[1] := '';
  254. SWord := '';
  255. StrVocalsWhichAlreadyWereInString := '';
  256.  
  257. i := 1;
  258. while (i <= Length(SInput)) do
  259. begin
  260. ChChar := SInput[i];
  261. if ((ChChar = ' ') or (i = Length(SInput))) then
  262. begin
  263. if (i = Length(SInput)) then
  264. SWord := SWord + ChChar;
  265. DecideWhatToDoWithFoundWord(ArrStrAnswer, SWord, StrConsonatsInFirstWord, StrLastWord, StrVocalsWhichAlreadyWereInString);
  266. SWord := '';
  267. end
  268. else
  269. SWord := SWord + ChChar;
  270. Inc(i);
  271. end;
  272. writeln;
  273.  
  274. Result := ArrStrAnswer;
  275. end;
  276.  
  277. procedure OutputAnswer(ArrStrAnswer: TAnswer);
  278. var
  279. SShouldOutputInfoToFile, SPathToFile: String;
  280. BOutputIsReady: Boolean;
  281.  
  282. begin
  283. writeln('Ответ:' + #10 + #13 + ArrStrAnswer[0] + #10 + #13 + ArrStrAnswer[1]);
  284. end;
  285.  
  286. var
  287. StrInput, StrFirstWord, StrLastWord, StrConsonatsInFirstWord: String;
  288. ArrStrAnswer: TAnswer;
  289.  
  290. begin
  291. StrInput := GetInput();
  292. StrFirstWord := SearchForFirstWord(StrInput);
  293. StrConsonatsInFirstWord := FindConsonatsInWord(StrFirstWord);
  294. StrLastWord := SearchForLastWord(StrInput);
  295.  
  296. ArrStrAnswer := ComputeAnswer(StrInput, StrFirstWord, StrConsonatsInFirstWord, StrLastWord);
  297. OutputAnswer(ArrStrAnswer);
  298. readln;
  299. end.
Advertisement
Add Comment
Please, Sign In to add comment