Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Program LAB3_1;
- Uses
- System.SysUtils;
- Const
- SPACE = ' ';
- LETTERS = [#65 .. #90, #97 .. #122];
- Var
- SpaceCount, I, J, Len: Integer;
- IsOdd, HasLetters: Boolean;
- Text, Result, Word, OpenBrace, CloseBrace: String;
- WordsArr: Array Of String;
- Begin
- Writeln('Данная программа в каждом четном слове текста заменяет все буквы на прописные,',
- #10, 'а каждое нечетное слово заключает в круглые скобки.');
- Writeln('Введите текст.');
- Readln(Text);
- Len := Length(Text);
- I := 1;
- SpaceCount := 0;
- While I < Len + 1 Do
- Begin
- If Text[I] = SPACE Then
- Inc(SpaceCount);
- Inc(I);
- End;
- SetLength(WordsArr, SpaceCount + 1);
- I := 1;
- J := 0;
- While I < Len + 1 Do
- Begin
- If (Text[I] = SPACE) Then
- Inc(J)
- Else
- WordsArr[J] := WordsArr[J] + Text[I];
- Inc(I);
- End;
- I := 0;
- IsOdd := True;
- OpenBrace := '(';
- CloseBrace := ')';
- While I < High(WordsArr) + 1 Do
- Begin
- HasLetters := False;
- J := 1;
- Word := WordsArr[I];
- While (J < (Length(Word) + 1)) And Not HasLetters Do
- Begin
- If Word[J] In LETTERS Then
- HasLetters := True;
- Inc(J);
- End;
- If HasLetters Then
- If IsOdd Then
- Begin
- J := 1;
- While (J < Length(Word)) And Not(Word[J] In LETTERS) Do
- Inc(J);
- Insert(OpenBrace, WordsArr[I], J);
- Word := WordsArr[I];
- Inc(J);
- While (J < (Length(Word) + 1)) And (Word[J] In LETTERS) Do
- Inc(J);
- Insert(CloseBrace, WordsArr[I], J);
- IsOdd := False;
- End
- Else
- Begin
- WordsArr[I] := UpperCase(WordsArr[I]);
- IsOdd := True;
- End;
- Inc(I);
- End;
- For I := 0 To High(WordsArr) Do
- Result := Result + WordsArr[I] + SPACE;
- Writeln('Результат:', #10, Result);
- Readln;
- End.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement