Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // urs_2.cpp: определяет точку входа для консольного приложения.
- //
- #include "stdafx.h"
- #include <iostream>
- #include <string.h>
- #include <conio.h>
- #include <Windows.h>
- void in(char** &mass_f, char* &razd_f, int &num_f, int* &kol_f, int &kol_w_f, char* &str_f);
- void s_index(char** &txt_f, int &num_f, char** & rez_f, char* &razd_f, int &word_f, int* &index_f, int &kol_w_f, int &razm_i_f);
- int main()
- {
- setlocale(LC_ALL, ".1251");
- char **txt = (char**)malloc(sizeof(char*) * 1);
- txt[0] = (char*)malloc(sizeof(char) * 1);
- char *razd = (char*)malloc(sizeof(char)*81);
- int num = 0;
- int *kol = (int*)malloc(sizeof(int)*1);
- int kol_w = 0;
- char *str = (char*)malloc(sizeof(char)*1);
- char **rez;
- int word = 0;
- int razm_i;
- int *index = (int*)malloc(sizeof(int)*1);
- in(txt, razd, num, kol, kol_w, str);
- s_index(txt, num, rez, razd, word, index, kol_w, razm_i);
- system("pause");
- return 0;
- }
- void in(char** &mass_f, char* &razd_f, int &num_f, int* &kol_f, int &kol_w_f, char* &str_f)
- {
- int sr_kol = 0;
- int p_kol = 0;
- int f_3 = 1;
- puts("Введите символы-разделители");
- scanf("%s", razd_f);
- do{
- char *str = (char*)malloc(sizeof(char) * 256);
- printf("Введите строку [%d]\n", (num_f + 1));
- scanf("%s", str);
- kol_f = (int*)realloc(kol_f, sizeof(int)*(num_f + 1));
- int len = strlen(str);
- int r_len = strlen(razd_f);
- mass_f = (char**)realloc(mass_f, sizeof(char*)*(num_f + 1));
- mass_f[num_f] = NULL;
- mass_f[num_f] = (char*)realloc(mass_f[num_f], sizeof(char)*(len + 1));
- strcpy(mass_f[num_f], str);
- int f = 1;
- int r_word = 0;
- int f_2 = 0;
- for (int i = 0; i < len; i++)
- {
- for (int j = 0; j < r_len; j++)
- {
- char a = str[i], b = razd_f[j];
- if (str[i] != razd_f[j] && f == 1)
- {
- f = 1;
- }
- else
- {
- f = 0;
- }
- }
- if (f == 1)
- {
- r_word++;
- }
- f = 1;
- }
- kol_f[num_f] = r_word;
- p_kol = p_kol + kol_f[num_f];
- if (num_f != 0)
- {
- sr_kol = (p_kol - kol_f[num_f]) / (num_f);
- }
- if (sr_kol == kol_f[num_f])
- {
- f_3 = 0;
- }
- num_f++;
- } while (f_3 == 1);
- puts("Введите количество слов: ");
- scanf("%d", &kol_w_f);
- puts("Введите строку для вставки: ");
- int i = 0;
- while ((str_f[i] = getch()) != '\r')
- {
- i++;
- str_f = (char*)realloc(str_f, (i + 1)*sizeof(char));
- }
- str_f[i] = '\0';
- }
- void s_index(char** &txt_f, int &num_f, char** &rez_f, char* &razd_f, int &word_f, int* &index_f, int &kol_w_f, int &razm_i_f)
- {
- int flag = 0;
- word_f = 0;
- for (int i = 0; i < num_f; i++)
- {
- int len = strlen(txt_f[i]);
- for (int j = 0; j < len; j++)
- {
- int r_len = strlen(razd_f);
- for (int k = 0; (k < r_len )&& (flag = 0); k++)
- {
- if (txt_f[i][j] != razd_f[k])
- {
- flag = 1;
- }
- }
- }
- if (flag == 1)
- {
- word_f++;
- }
- if (word_f == kol_w_f)
- {
- razm_i_f = 0;
- index_f = (int*)realloc(index_f, sizeof(int)*(razm_i_f++));
- index_f[razm_i_f] = num_f;
- razm_i_f++;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment