program Pascal_169226;
var
str,fWord,lWord:String;
fDelim,lDelim:Integer;
begin
{* Вводим строку *}
WriteLn('Input string:');
ReadLn(str);
{* Позиция первого разделителя *}
fDelim:=1;
{* Позиция последнего разделителя *}
lDelim:=Length(str);
{* Ищем первый разделитель *}
while fDelim<=lDelim do begin
if (str[fDelim]=',') or (str[fDelim]=' ') then begin
break;
end;
Inc(fDelim);
end;
{* Ищем последний разделитель *}
while fDelim<=lDelim do begin
if (str[lDelim]=',') or (str[lDelim]=' ') then begin
break;
end;
Dec(lDelim);
end;
if fDelim>lDelim then begin
WriteLn('This is one word');
end else begin
{* Копируем первое слово *}
fWord:=copy(str,1,fDelim-1);
{* Копируем последнее слово *}
lWord:=copy(str,lDelim+1,Length(str)-lDelim);
{* Собираем новую строку *}
str:=lWord+copy(str,fDelim,lDelim-fDelim+1)+fWord;
{* Выводим результат *}
WriteLn('Result string:');
WriteLn(str);
end;
ReadLn;
end.
Input string:
This is a test string
Result string:
string is a test This
Если Вы уже зарегистрированы на Портале - войдите в систему, если Вы еще не регистрировались - пройдите простую процедуру регистрации.