Advertisement
Guest User

Untitled

a guest
Feb 19th, 2020
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 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],tempw1[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. strncpy_s(tempw1, tempw, y);
  69. if (strcmp(tempw1,checkw)==0)
  70. {
  71. q++;
  72. j++;
  73. }
  74.  
  75. } else j++;
  76. }
  77. cout << "В" << i+1 << "строке " << q <<endl;
  78. }
  79. }
  80.  
  81. int main(void)
  82. {
  83. SetConsoleCP(1251);
  84. SetConsoleOutputCP(1251);
  85. char** mas;
  86. mas = new char* [n];
  87. for (int i = 0; i < n; i++)
  88. mas[i] = new char[m];
  89. int k = masinput(mas, n);
  90. strsearch(mas, k);
  91.  
  92. for (int i = 0; i < n; i++)
  93. delete[] mas[i];
  94. delete[] mas;
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement