-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathТекст.pas
More file actions
37 lines (37 loc) · 769 Bytes
/
Текст.pas
File metadata and controls
37 lines (37 loc) · 769 Bytes
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
27
28
29
30
31
32
33
34
35
36
37
{$H+}
program ztext;
var
f1,f2: text;
k,i,cnt,pos: integer;
s,s1: string;
label goback;
begin
AssignFile(f1,'text.in');
AssignFile(f2,'text.out');
reset(f1);
readln(f1,k);
readln(f1,s);
close(f1);
rewrite(f2);
goback:
cnt := 0; //счетчик длины текущего куска
for i := low(s) to high(s) do
begin
if(s[i]=' ') and (s[i+1]=' ') then
begin
delete(s,i+1,1);
GOTO goback;
end;
inc(cnt); //счетчик длины слова
if(s[i]=' ') then pos := i;//запоминаем позицию пробела
if (cnt > k) then
begin
s1 := copy(s,low(s),pos-1);
delete(s,low(s),pos);
writeln(f2,s1);
GOTO goback;
end;
end;
write(f2,s);
close(f2);
end.