Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream> //библиотека с простыми манипуляторами
- #include <iomanip> //библиотека с параметризированными манипуляторами
- #include <string.h>
- using namespace std; //подключение пространства имён
- const int n=10, m=80, b=20;
- int masinput(char **mas, int n)
- {
- cout<<"Введите текст"<<endl;
- int w=0;
- while (w<n)
- {
- cin.getline(mas[w],m);
- if ((strcmp(mas[w],"")==0)) break;
- w++;
- }
- if ((strcmp(mas[w],"")==0))
- return w;
- return w+1;
- }
- bool puncts(char ch)
- {
- char str[]=".,!?;:-()";
- if (strchr(str,ch)) return true;
- else return false;}
- bool spaces(char ch)
- {
- if (ch==' '||ch=='\t'||ch=='\n'||ch=='\v'||ch=='\0')
- return true;
- else return false;
- }
- int wordsearch (char **mas, int q)
- {
- cout<<"Введите слово для поиска"<<endl;
- char word[b];
- cin.getline(word,b);
- int n=0,l=0,wl=0;
- long int d=0,p=0;
- p=strlen(word);
- for (int i=0;i<q;i++)
- {
- d=strlen(mas[i]);
- for (int j=0;j<d;)
- {
- if (!spaces(mas[i][j])&&!puncts(mas[i][j]))
- {
- while (!spaces(mas[i][j])&&!puncts(mas[i][j]))
- {
- wl++;
- j++;
- }
- for (int z=0;z<b;z++)
- if (p==wl&&word[z]==mas[i][j])
- {
- j++;
- }
- n++;
- //cout<<n<<"слово"<<endl;
- }
- }
- else j++;
- }
- }
- return 0;
- }
- cout<<n<<endl;
- n=0;
- }
- int main(void) //главная функция
- {
- //руссификация консоли
- setlocale(LC_ALL, "RUSSIAN");
- //переменные
- char **mas;
- mas=new char *[n];
- for (int i=0; i<n; i++)
- mas[i]=new char [m];
- int q=masinput(mas,n);
- int kword=wordsearch(mas,q);
- //cout<<kword<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment