begin var s := ReadlnString('s = '); var s1 := ''; var i := 1;
repeat var t := pos(' ', s, i + 1);
if ((s[i] = ' ') or (i = 1)) and (((t = 0) and (Length(s) - i = wordl)) or (t - i - 1 = wordl)) then i := i + wordl + 1 else begin s1 := s1 + s[i]; i := i + 1; end; until i > length(s);
Var S: string; i, k: integer; b: boolean; begin readln(s); var n := Length(s); i := 1; repeat b := true; while (i <= n) and (s[i] <> ' ') do begin if b then begin k := i; b := false end; inc(i) end; if i - k = 4 then begin delete(s, k, 5); i := k; n := n - 5 end else inc(i) until i > n; write(s) end.
1 votes Thanks 0
archery
как по мне немного понятнее первого ответа
Answers & Comments
const
wordl = 4;
begin
var s := ReadlnString('s = ');
var s1 := '';
var i := 1;
repeat
var t := pos(' ', s, i + 1);
if ((s[i] = ' ') or (i = 1))
and (((t = 0) and (Length(s) - i = wordl)) or (t - i - 1 = wordl))
then
i := i + wordl + 1
else begin
s1 := s1 + s[i];
i := i + 1;
end;
until i > length(s);
writeln(s1)
end.
Verified answer
VarS: string;
i, k: integer;
b: boolean;
begin
readln(s);
var n := Length(s);
i := 1;
repeat
b := true;
while (i <= n) and (s[i] <> ' ') do
begin
if b then
begin
k := i;
b := false
end;
inc(i)
end;
if i - k = 4 then
begin
delete(s, k, 5);
i := k;
n := n - 5
end
else inc(i)
until i > n;
write(s)
end.