Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Program Lab3_1;
- Uses
- System.SysUtils;
- Var
- J, PrevJ, NumWord: Integer;
- Text, NewText: String;
- IsNumWordEven: Boolean;
- Procedure PrintCondition();
- Begin
- Writeln('Данная программа выведет каждое нечетное слово в кавычках, а каждое четное - в квадратных скобках');
- Writeln('Введите текст:');
- End;
- Function ReadText(): String;
- Var
- TextIn: String;
- Begin
- Readln(TextIn);
- ReadText := TextIn;
- End;
- Function GetNextSpaceIndex(Text: String; PrevI: Integer): Integer;
- Var
- I: Integer;
- C: Char;
- Begin
- I := PrevI;
- Repeat
- Inc(I);
- C := Text[I];
- Until ((C = #32) Or (I = Length(Text)));
- GetNextSpaceIndex := I;
- End;
- Function GetNewWord(Var Text: String; Var I: Integer; PrevI: Integer; IsNumWordEven: Boolean): String;
- Var
- NumWord, NextI: Integer;
- Word: String;
- BeginSym, EndSym: Char;
- Begin
- NextI := GetNextSpaceIndex(Text, PrevI);
- I := PrevI + 1;
- If IsNumWordEven Then
- Begin
- BeginSym := '[';
- EndSym := ']';
- End
- Else
- Begin
- BeginSym := '"';
- EndSym := '"';
- End;
- Word := BeginSym;
- Repeat
- Word := Word + Text[I];
- Inc(I);
- Until (I = NextI);
- Word := Word + EndSym;
- GetNewWord := Word;
- End;
- Begin
- PrintCondition();
- Text := ReadText();
- Text := Text + ' ';
- NumWord := 1;
- J := 0;
- Repeat
- PrevJ := J;
- If NumWord Mod 2 = 1 Then
- IsNumWordEven := False
- Else
- IsNumWordEven := True;
- NewText := NewText + GetNewWord(Text, J, PrevJ, IsNumWordEven) + ' ';
- Inc(NumWord);
- Until J = Length(Text);
- Writeln(NewText);
- Readln;
- End.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement