Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <Windows.h>
- using namespace std;
- int main() {
- //установка кириллицы в консоле
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);
- //ввод
- cout << "Введите текст" << endl;
- string s;
- getline(cin, s);
- string newS;
- int numWord = 1;
- for (int i = 0; i < s.length(); i++) {
- if (s[i] == ' ') {
- if (numWord % 2 == 0) {
- int j = i - 1;
- while (j >= 0 && s[j] != ' ') newS += s[j--];
- newS += ' ';
- }
- numWord++;
- }
- }
- if (numWord % 2 == 0) {
- int j = s.length() - 1;
- while (j >= 0 && s[j] != ' ') newS += s[j--];
- }
- //вывод
- cout << "Результат обработки:" << endl << newS << endl;
- //задержка консоли
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement