Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program Lab3_1;
- uses System.SysUtils, System.StrUtils;
- Const
- Separators = ' ,.:;-?!()[]{}@#$%&';
- var
- Input: String;
- function GetEndIndex(str: String; I: Integer): Integer;
- begin
- while not(ContainsText(Separators, str[I])) do
- begin
- inc(I)
- end;
- dec(I);
- GetEndIndex := I;
- end;
- function GetNextWordIndex(str: String; I: Integer): Integer;
- begin
- inc(I);
- while (ContainsText(Separators, str[I])) do
- begin
- inc(I)
- end;
- GetNextWordIndex := I;
- end;
- function GetWord(str: String; fromIndex, ToIndex: Integer): String;
- var
- I: Integer;
- ret: string;
- begin
- ret := '';
- if ToIndex > high(str) then
- ToIndex := high(str);
- for I := fromIndex to ToIndex do
- ret := ret + str[I];
- GetWord := ret;
- end;
- function Swap(str: String): String;
- var
- I, firstEndIndex, secondStartIndex, secondEndIndex: Integer;
- ret, Word1, Word2, Splitter, temp: String;
- begin
- I := 1;
- while I < Length(str)+1 do
- begin
- if ContainsText(Separators, str[I]) then
- begin
- ret := ret + str[I];
- end
- else
- begin
- firstEndIndex := GetEndIndex(str, I);
- secondStartIndex := GetNextWordIndex(str, firstEndIndex);
- secondEndIndex := GetEndIndex(str, secondStartIndex);
- Word1 := GetWord(str, I, firstEndIndex);
- Word2 := GetWord(str, secondStartIndex, secondEndIndex);
- Splitter := GetWord(str, firstEndIndex + 1, secondStartIndex - 1);
- I := secondEndIndex;
- ret := ret + Word2 + Splitter + Word1;
- end;
- inc(I);
- end;
- Swap := ret;
- end;
- begin
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement