Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include "stdafx.h"
- #include "stdafx.h"
- #include <math.h>
- #include <iostream>
- #include <windows.h>
- #include <fstream>
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #include <cstdlib>
- #include <ctime>
- #include <crtdbg.h>
- #include <conio.h>
- #include <string.h>
- #define _CRTBG_MAP_ALLOC
- #pragma warning(disable : 4996)
- using namespace std;
- int printMenu(int n);
- int delStr(char *&str);
- int getStr(char *&str);
- void processStr(char *&str);
- int main()
- {
- setlocale(LC_ALL, "Russian");
- setlocale(LC_ALL, "rus");
- int menu = 0;
- int check1 = 0;
- int check2 = 0;
- char *str = new char[1];
- str[0] = '\0';
- do
- {
- menu = printMenu(1);
- switch (menu)
- {
- case 1:
- {
- check2 = delStr(str);
- check1 = getStr(str);
- break;
- }
- case 2:
- {
- if (check1 == 1)
- {
- cout << str << endl;
- }
- break;
- }
- case 3:
- { if (check1 == 1)
- {
- processStr(str);
- }
- break;
- }
- case 0:
- {
- menu = 0;
- break;
- }
- default:
- {
- cout << "неверный пункт меню!!\a" << endl;
- break;
- }
- }
- } while (menu != 0);
- _CrtDumpMemoryLeaks();
- return 0;
- }
- int printMenu(int n)
- {
- if (n == 1)
- {
- cout << " +----------------------------------+ \n";
- cout << " | Выберите команду: | \n";
- cout << " |----------------------------------| \n";
- cout << " | 1-ввести строку | \n";
- cout << " |----------------------------------| \n";
- cout << " | 2-вывести строку | \n";
- cout << " |----------------------------------| \n";
- cout << " | 3-обработать строку | \n";
- cout << " |----------------------------------| \n";
- cout << " | 0-выход: | \n";
- cout << " +----------------------------------+ \n";
- }
- int menuMain = 0;
- cin >> menuMain;
- return menuMain;
- }
- int delStr(char *&str)
- {
- if ((strlen(str)>0) && (str != NULL))
- {
- delete[] str;
- }
- str = new char[1];
- str[0] = '\0';
- return 0;
- }
- int getStr(char *&str)
- {
- char ch = 0;
- char *tmp = NULL;
- while (true)
- {
- int len = 0;
- ch = getch();
- printf("%c", ch);
- if (ch == 13)
- {
- break;
- }
- len = strlen(str);
- tmp = new char[len + 2];
- strcpy(tmp, str);
- tmp[len] = ch;
- tmp[len + 1] = '\0';
- delete[] str;
- str = tmp;
- }
- return 1;
- }
- void processStr(char *&str)
- {
- int count = 0;
- int posmin = 0;
- int countmin = strlen(str);
- for (int i = 0; i < strlen(str);)
- {
- while (str[i] && !isalpha(str[i])) ++i;
- if (str[i] == 0) break;
- int pos = i;
- while (str[i] && isalpha(str[i])) ++i;
- count = i - pos;
- if (count < countmin)
- {
- countmin = count;
- posmin = pos;
- }
- }
- for (int i = posmin; i < posmin + countmin; ++i)
- putchar(str[i]);
- putchar('\n');
- printf("Len = %d, pos = %d\n", countmin, posmin);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement