Advertisement
Kentoo

A#3

Dec 17th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.31 KB | None | 0 0
  1. // ConsoleApplication2.cpp: определяет точку входа для консольного приложения.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. #include <string>
  7. #include "windows.h"
  8.  
  9. using namespace std;
  10. void main()
  11. {
  12.     int kol = 0;
  13.     setlocale(LC_ALL, "Russian");
  14.     SetConsoleCP(1251);
  15.     SetConsoleOutputCP(1251);
  16.     string str, str1, str2, str3;
  17.     cout << "Введите строку" << endl;
  18.     getline(cin, str);
  19.     while (str.find(" а ") != string::npos) {
  20.         str.replace(str.find(" а "), 3, ",а ");
  21.         kol++;
  22.     }
  23.     while (str.find(" но ") != string::npos) {
  24.         str.replace(str.find(" но "), 4, ",но ");
  25.         kol++;
  26.     }
  27.     if (kol != 0) {
  28.         kol++;
  29.     }
  30.     cout << str << endl;
  31.     cout << "Количество подстрок = " << kol << endl;
  32.     str = str + " ,";
  33.     str1 = "";
  34.     while (str.find(',') != string::npos) {
  35.         str2 = str.substr(0, str.find(','));
  36.         str = str.substr(str.find(',') + 1, str.length());
  37.         str3 = str2.substr(0, str2.find(' '));
  38.         if (str3.compare("а") == 0 || str3.compare("но") == 0) {
  39.             str3 = str2.substr(str2.find(' ') + 1, str2.substr(str2.find(' ') + 1, str2.length()).find(' '));
  40.         }
  41.         str1 += str3 + ' ';
  42.     }
  43.     cout << "Строка, сформированная из первых слов подстрок :" << endl;
  44.     cout << str1;
  45.     system("pause");
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement