Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- #include <string>
- #include <locale.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <algorithm>
- #include <string.h>
- using namespace std;
- bool cmp(char* a, char* b) {
- int lena = strlen(a);
- int lenb = strlen(b);
- return lena < lenb;
- }
- int main()
- {
- setlocale(LC_ALL, "Russian");
- int n, i;
- cout << "количество фраз" << endl;
- scanf("%d", &n);
- char **arr_phrases = new char* [n];
- getchar();
- cout << "Введите фразы" << endl;
- for (i = 0; i < n; i++) {
- arr_phrases[i] = new char[1001];
- gets(arr_phrases[i]);
- }
- cout << "Введите слово" << endl;
- char word[1001];
- gets(word);
- int dlen = 0;
- for(int i = 0; i < n; i++) {
- if(strstr(arr_phrases[i], word) != NULL) {
- dlen++;
- }
- }
- char** N_arr_p = new char* [dlen];
- int pos = 0;
- for (int i = 0; i < n; i++) {
- if(strstr(arr_phrases[i], word) != NULL) {
- N_arr_p[pos++] = arr_phrases[i];
- arr_phrases[i] = "-1";
- }
- }
- // Все строки которые содержат word
- cout << "Строки содержащие слово " << word << endl;
- for(int i = 0; i < pos; i++) {
- cout << N_arr_p[i] << endl;
- }
- cout << "Введите тип сортировки(1 - по алфавиту, 2 - по длине)" << endl;
- int type;
- cin >> type;
- if(type == 1) {
- sort(N_arr_p, N_arr_p + pos); // сортировка по алфавиту
- } else {
- sort(N_arr_p, N_arr_p + pos, cmp); // сортировка массива с помощью компаратора cmp
- }
- cout << "Отсортированный массив " << word << endl;
- for(int i = 0; i < pos; i++) {
- cout << N_arr_p[i] << endl;
- }
- }
Add Comment
Please, Sign In to add comment