Advertisement
Guest User

Untitled

a guest
Feb 19th, 2020
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <string.h>
  4. #include <windows.h>
  5.  
  6. using namespace std;
  7.  
  8. const int n = 10, m = 80, b=20;
  9.  
  10. int masinput(char** mas, int n) //функция ввода массива
  11. {
  12. cout << "Введите текст" << endl;
  13. int k = 0;
  14. while (k < n)
  15. {
  16. cin.getline(mas[k], m);
  17. if ((strcmp(mas[k], "") == 0)) break;
  18. k++;
  19. }
  20. if ((strcmp(mas[k], "") == 0))
  21. return k;
  22. return k + 1;
  23. }
  24.  
  25. bool spaces(char ch)
  26.  
  27. {
  28.  
  29. if (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\v' || ch == '\0' || ch == '\f' || ch == ' ') return true;
  30.  
  31. else return false;
  32.  
  33. }
  34. bool puncts(char ch)
  35.  
  36. {
  37.  
  38. char str[] = ".,!?;:-()";
  39.  
  40. if (strchr(str, ch)) return true;
  41.  
  42. else return false;
  43. }
  44. void strsearch(char** mas, int k)
  45. {
  46. int checkwlen = 0, q, y;
  47. cout << "Введите слово для поиска" << endl;
  48. char checkw[m], tempw[m];
  49. cin.getline(checkw, m);
  50. checkwlen = strlen(checkw);
  51. for (int i = 0; i < k; i++)
  52. {
  53. q = 0; // кол-во слов в строке
  54. for (int j = 0; j < strlen(mas[i]);)
  55. {
  56. for (int t = 0; t < 80; t++)
  57. tempw[t] = ' ';
  58.  
  59. if (!spaces(mas[i][j]) && !puncts(mas[i][j]))
  60. {
  61. y = 0;
  62. while (!spaces(mas[i][j]) && !puncts(mas[i][j]))
  63. {
  64. tempw[y] = mas[i][j];
  65. j++;
  66. y++;
  67. }
  68. if (strspn(checkw,tempw) == checkwlen)
  69. {
  70. q++;
  71. j++;
  72. }
  73.  
  74. } else j++;
  75. }
  76. cout << "В" << i+1 << "строке " << q <<endl;
  77. }
  78. }
  79.  
  80. int main(void)
  81. {
  82. SetConsoleCP(1251);
  83. SetConsoleOutputCP(1251);
  84. char** mas;
  85. mas = new char* [n];
  86. for (int i = 0; i < n; i++)
  87. mas[i] = new char[m];
  88. int k = masinput(mas, n);
  89. strsearch(mas, k);
  90.  
  91. for (int i = 0; i < n; i++)
  92. delete[] mas[i];
  93. delete[] mas;
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement