Text30. Дан текстовый файл. Вывести последнее слово текста наименьшей длины. Словом считать набор символов, не содержащий пробелов и ограниченный пробелами или началом/концом строки.
Решение:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
program Text30; var F: Text; Name,S,Word: string; begin Write('File name: '); Readln(Name); Assign(F,Name); Reset(F); Word:=''; While not eof(F) do begin Readln(F,S); While (pos(' ',S)<>0) do begin if ((pos(' ',S)-1<length(Word)) or (length(Word)=0)) and (pos(' ',S)<>1) then Word:=Copy(S,1,pos(' ',S)-1) Else Delete(S,1,pos(' ',S)); end; if ((length(S)<length(Word)) or (length(Word)=0)) and (length(S)>0) then Word:=S; end; Close(F); Writeln(Word); end. |
Другие задачи из раздела Text можно посмотреть здесь.
Комментарии: