Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <string.h>
- #include <windows.h>
- using namespace std;
- const int n = 10, m = 80, b=20;
- int masinput(char** mas, int n) //функция ввода массива
- {
- cout << "Введите текст" << endl;
- int k = 0;
- while (k < n)
- {
- cin.getline(mas[k], m);
- if ((strcmp(mas[k], "") == 0)) break;
- k++;
- }
- if ((strcmp(mas[k], "") == 0))
- return k;
- return k + 1;
- }
- bool spaces(char ch)
- {
- if (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\v' || ch == '\0' || ch == '\f' || ch == ' ') return true;
- else return false;
- }
- bool puncts(char ch)
- {
- char str[] = ".,!?;:-()";
- if (strchr(str, ch)) return true;
- else return false;
- }
- void strsearch(char** mas, int k)
- {
- int checkwlen = 0, q, y;
- cout << "Введите слово для поиска" << endl;
- char checkw[m], tempw[m];
- cin.getline(checkw, m);
- checkwlen = strlen(checkw);
- for (int i = 0; i < k; i++)
- {
- q = 0; // кол-во слов в строке
- for (int j = 0; j < strlen(mas[i]);)
- {
- for (int t = 0; t < 80; t++)
- tempw[t] = ' ';
- if (!spaces(mas[i][j]) && !puncts(mas[i][j]))
- {
- y = 0;
- while (!spaces(mas[i][j]) && !puncts(mas[i][j]))
- {
- tempw[y] = mas[i][j];
- j++;
- y++;
- }
- if (strspn(checkw,tempw) == checkwlen)
- {
- q++;
- j++;
- }
- } else j++;
- }
- cout << "В" << i+1 << "строке " << q <<endl;
- }
- }
- int main(void)
- {
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);
- char** mas;
- mas = new char* [n];
- for (int i = 0; i < n; i++)
- mas[i] = new char[m];
- int k = masinput(mas, n);
- strsearch(mas, k);
- for (int i = 0; i < n; i++)
- delete[] mas[i];
- delete[] mas;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement