Advertisement
Guest User

Untitled

a guest
Nov 21st, 2017
328
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.94 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include "stdafx.h"
  3. #include "stdafx.h"
  4. #include <math.h>
  5. #include <iostream>
  6. #include <windows.h>
  7. #include <fstream>
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <time.h>
  11. #include <cstdlib>
  12. #include <ctime>
  13. #include <crtdbg.h>
  14. #include <conio.h>
  15. #include <string.h>
  16. #define _CRTBG_MAP_ALLOC
  17. #pragma warning(disable : 4996)
  18. using namespace std;
  19.  
  20. int printMenu(int n);
  21. int delStr(char *&str);
  22. int getStr(char *&str);
  23. void processStr(char *&str);
  24.  
  25.  
  26.  
  27.  
  28. int main()
  29. {
  30.  
  31. setlocale(LC_ALL, "Russian");
  32. setlocale(LC_ALL, "rus");
  33.  
  34. int menu = 0;
  35. int check1 = 0;
  36. int check2 = 0;
  37. char *str = new char[1];
  38. str[0] = '\0';
  39. do
  40. {
  41.  
  42. menu = printMenu(1);
  43. switch (menu)
  44. {
  45. case 1:
  46. {
  47. check2 = delStr(str);
  48. check1 = getStr(str);
  49.  
  50. break;
  51. }
  52. case 2:
  53. {
  54. if (check1 == 1)
  55. {
  56. cout << str << endl;
  57.  
  58. }
  59.  
  60. break;
  61. }
  62. case 3:
  63. { if (check1 == 1)
  64. {
  65. processStr(str);
  66. }
  67. break;
  68. }
  69. case 0:
  70. {
  71. menu = 0;
  72. break;
  73. }
  74. default:
  75. {
  76. cout << "неверный пункт меню!!\a" << endl;
  77. break;
  78. }
  79.  
  80. }
  81.  
  82.  
  83. } while (menu != 0);
  84.  
  85.  
  86.  
  87.  
  88. _CrtDumpMemoryLeaks();
  89. return 0;
  90.  
  91. }
  92. int printMenu(int n)
  93. {
  94. if (n == 1)
  95. {
  96. cout << " +----------------------------------+ \n";
  97. cout << " | Выберите команду: | \n";
  98. cout << " |----------------------------------| \n";
  99. cout << " | 1-ввести строку | \n";
  100. cout << " |----------------------------------| \n";
  101. cout << " | 2-вывести строку | \n";
  102. cout << " |----------------------------------| \n";
  103. cout << " | 3-обработать строку | \n";
  104. cout << " |----------------------------------| \n";
  105. cout << " | 0-выход: | \n";
  106. cout << " +----------------------------------+ \n";
  107. }
  108. int menuMain = 0;
  109. cin >> menuMain;
  110. return menuMain;
  111. }
  112. int delStr(char *&str)
  113. {
  114. if ((strlen(str)>0) && (str != NULL))
  115. {
  116. delete[] str;
  117. }
  118. str = new char[1];
  119. str[0] = '\0';
  120. return 0;
  121. }
  122. int getStr(char *&str)
  123. {
  124. char ch = 0;
  125. char *tmp = NULL;
  126. while (true)
  127. {
  128. int len = 0;
  129. ch = getch();
  130. printf("%c", ch);
  131. if (ch == 13)
  132. {
  133. break;
  134. }
  135. len = strlen(str);
  136. tmp = new char[len + 2];
  137. strcpy(tmp, str);
  138. tmp[len] = ch;
  139. tmp[len + 1] = '\0';
  140.  
  141. delete[] str;
  142. str = tmp;
  143. }
  144. return 1;
  145.  
  146.  
  147. }
  148. void processStr(char *&str)
  149. {
  150. int count = 0;
  151. int posmin = 0;
  152. int countmin = strlen(str);
  153. for (int i = 0; i < strlen(str);)
  154. {
  155. while (str[i] && !isalpha(str[i])) ++i;
  156. if (str[i] == 0) break;
  157. int pos = i;
  158. while (str[i] && isalpha(str[i])) ++i;
  159. count = i - pos;
  160. if (count < countmin)
  161. {
  162. countmin = count;
  163. posmin = pos;
  164. }
  165. }
  166.  
  167. for (int i = posmin; i < posmin + countmin; ++i)
  168. putchar(str[i]);
  169. putchar('\n');
  170. printf("Len = %d, pos = %d\n", countmin, posmin);
  171. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement