Program Example_2;
Var i,n:integer;
St:string;
Begin
Write ('Введіть текст: ');
readln(St);
n:=length(St);
for i:=1 to n do begin
if St[i]='.' then St[i]:='...';
if St[i]=':' then St[i]:='-';
end;
writeln(St);
end.
Program Zamena;
var
strInput,strOutput,strTemp:string;
intI:integer;
begin
writeln('vvedite stroku');
readln(strInput);
for intI:=1 to length(strInput) do begin
case strInput[intI] of
'.':strTemp:='...';
':':strTemp:='-';
'-':strTemp:=':';
else strTemp:=strInput[intI];
end; {case}
strOutput:=strOutput+strTemp;
end;
writeln(strOutput);
readln;
end.
Код:
vvedite stroku
hello world ... Hello:word hellow - world
hello world ......... Hello-word hellow : world
Program Example_2;
Uses crt;
Var i: byte;
St,tmp: string;
Begin
Clrscr;
Write('Vv text.. ');
readln(St);
i:=1;
while i<= length(St) do begin
if St[i]= ':' then begin
St[i]:= '-';
inc(i);
continue;
end;
if St[i]= '-' then begin
St[i]:= ':';
inc(i);
continue;
end;
if St[i]= '.' then begin
insert('..',St,i);
i:=i+2;
end;
inc(i);
end;
Writeln(St);
readln
end.
С циклом FOR почему-то уходит в вечный луп если ввести всего одну точку. А с вайлом вроде всё норм. Удачи!