Advertisement
Caneq

lb4.3.2

Dec 12th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.15 KB | None | 0 0
  1. #include "pch.h"
  2. #include <string.h>
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8.     const int MAX = 4000;
  9.     char str[MAX];
  10.     char new_str[MAX + 1] = { 0 };
  11.     const char DELIMS[] = " .,:;!?-\'()";
  12.  
  13.     cout << "Enter a string: ";
  14.     cin.getline(str, MAX);
  15.     int len = strlen(str);
  16.  
  17.     for (int i = 0; i <= len; i++) {
  18.         for (int j = 0; DELIMS[j]; j++) {
  19.             if (str[i] == DELIMS[j]) {
  20.                 str[i] = 0;
  21.             }
  22.         }
  23.     }
  24.     char* pLast = str + len - 1;
  25.     for (; *pLast; pLast--) {};
  26.     pLast += 1;
  27.  
  28.     bool flag = false;
  29.     int o1 = 0;
  30.     int o2 = -1;
  31.     for (int i = 0; i <= len; i++) {
  32.         if (!str[i]) {
  33.             o1 = o2;
  34.             o2 = i;
  35.             bool flag = false;
  36.             for (int j = o1 + 1; j < o2; j++) {
  37.                 for (int k = 0; pLast[k]; k++) {
  38.                     if (str[j] == pLast[k]) {
  39.                         flag = true;
  40.                         break;
  41.                     }
  42.                 }
  43.                 if (!flag) {
  44.                     break;
  45.                 }
  46.                 if (flag && str[j + 1]) {
  47.                     flag = false;
  48.                 }
  49.             }
  50.             if (flag) {
  51.                 strcat_s(new_str, MAX, str + o1 + 1);
  52.                 int len = strlen(new_str);
  53.                 new_str[len] = ' ';  //костыль для пробела
  54.                 new_str[len + 1] = 0;//
  55.             }
  56.         }
  57.     }
  58.     cout << new_str << endl;
  59.     system("pause");
  60.     return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement