Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <clocale>
- #include <cstdio>
- #include <cstdlib>
- #include <memory.h>
- #include <cstring>
- #include <Windows.h>
- #include <crtdbg.h>
- #include <string.h>
- #include <conio.h>
- using namespace std;
- void PrintMenu();
- char* Create();
- int Count(char* s);
- int main()
- {
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);
- int menu = 0;
- char* s = NULL;
- int count = 0;
- bool f = false;
- do
- {
- PrintMenu();
- cin >> menu;
- switch (menu)
- {
- case 1:
- {
- if (s != NULL)
- {
- delete[] s;
- count = 0;
- cout << "Массив очищен\n";
- }
- s = Create();
- break;
- }
- case 2:
- {
- if ((s == NULL) || (s[0] == 13))
- {
- cout << "Сначала введите строку\n";
- }
- else
- {
- count = Count(s);
- f = true;
- }
- break;
- }
- case 3:
- {
- if (f == false)
- {
- cout << "Сначала нужно обработать строку\n";
- }
- else
- {
- if ((s == NULL) || (s[0] == 13))
- {
- cout << "Сначала введите строку\n";
- }
- else
- {
- cout << "количество четырехбуквенных слов = " << count << "\n";
- f = false;
- }
- }
- break;
- }
- case 0:
- {
- break;
- }
- default:
- cout << "Такого варианта нет.\n";
- }
- } while (menu != 0);
- delete[] s;
- return 0;
- }
- void PrintMenu()
- {
- cout << "-------------------\n";
- cout << "1.Ввод \n";
- cout << "2.Обработка\n";
- cout << "3.Вывод\n";
- cout << "0.Выход\n";
- cout << "-------------------\n";
- }
- int Count(char* s)
- {
- int count = 0;
- int cur = 0;
- int i = 0;
- while (s[i] != '\0')
- {
- if ((s[i] != ' ') && (s[i] != ',') && (s[i] != '.') && (s[i] != '!') && (s[i] != '?')
- && (s[i] != ':') && (s[i] != ';'))
- {
- cur++;
- }
- else
- {
- if (cur == 4)
- {
- count++;
- }
- cur = 0;
- }
- i++;
- }
- if (cur == 4)
- count++;
- return count;
- }
- char* Create()
- {
- int len = 0;
- char* s = NULL;
- cout << "Введите строку\n";
- s = new char[1];
- s[0] = '\0';
- char ch = 0;
- while (true)
- {
- ch = getchar();
- if (ch == '\n')
- {
- break;
- }
- len = strlen(s);
- char* tmp = new char[len + 2];
- strcpy(tmp, s);
- tmp[len] = ch;
- tmp[len + 1] = '\0';
- delete[] s;
- s = tmp;
- }
- return s;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement