Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <string.h>
- #include <iostream>
- using namespace std;
- int main() {
- const int MAX = 4000;
- char str[MAX];
- char new_str[MAX + 1] = { 0 };
- const char DELIMS[] = " .,:;!?-\'()";
- cout << "Enter a string: ";
- cin.getline(str, MAX);
- int len = strlen(str);
- for (int i = 0; i <= len; i++) {
- for (int j = 0; DELIMS[j]; j++) {
- if (str[i] == DELIMS[j]) {
- str[i] = 0;
- }
- }
- }
- char* pLast = str + len - 1;
- for (; *pLast; pLast--) {};
- pLast += 1;
- bool flag = false;
- int o1 = 0;
- int o2 = -1;
- for (int i = 0; i <= len; i++) {
- if (!str[i]) {
- o1 = o2;
- o2 = i;
- bool flag = false;
- for (int j = o1 + 1; j < o2; j++) {
- for (int k = 0; pLast[k]; k++) {
- if (str[j] == pLast[k]) {
- flag = true;
- break;
- }
- }
- if (!flag) {
- break;
- }
- if (flag && str[j + 1]) {
- flag = false;
- }
- }
- if (flag) {
- strcat_s(new_str, MAX, str + o1 + 1);
- int len = strlen(new_str);
- new_str[len] = ' '; //костыль для пробела
- new_str[len + 1] = 0;//
- }
- }
- }
- cout << new_str << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement