golfflower

dimna

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