Silent1Snow

Untitled

Dec 20th, 2014
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.08 KB | None | 0 0
  1. // urs_2.cpp: определяет точку входа для консольного приложения.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. #include <string.h>
  7. #include <conio.h>
  8. #include <Windows.h>
  9.  
  10. void in(char** &mass_f, char* &razd_f, int &num_f, int* &kol_f, int &kol_w_f, char* &str_f);
  11. 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);
  12.  
  13. int main()
  14. {
  15.     setlocale(LC_ALL, ".1251");
  16.     char **txt = (char**)malloc(sizeof(char*) * 1);
  17.     txt[0] = (char*)malloc(sizeof(char) * 1);
  18.     char *razd = (char*)malloc(sizeof(char)*81);
  19.     int num = 0;
  20.     int *kol = (int*)malloc(sizeof(int)*1);
  21.     int kol_w = 0;
  22.     char *str = (char*)malloc(sizeof(char)*1);
  23.     char **rez;
  24.     int word = 0;
  25.     int razm_i;
  26.     int *index = (int*)malloc(sizeof(int)*1);
  27.     in(txt, razd, num, kol, kol_w, str);
  28.     s_index(txt, num, rez, razd, word, index, kol_w, razm_i);
  29.     system("pause");
  30.     return 0;
  31. }
  32.  
  33. void in(char** &mass_f, char* &razd_f, int &num_f, int* &kol_f, int &kol_w_f, char* &str_f)
  34. {
  35.     int sr_kol = 0;
  36.     int p_kol = 0;
  37.     int f_3 = 1;
  38.     puts("Введите символы-разделители");
  39.     scanf("%s", razd_f);
  40.     do{
  41.         char *str = (char*)malloc(sizeof(char) * 256);
  42.         printf("Введите строку [%d]\n", (num_f + 1));
  43.         scanf("%s", str);
  44.         kol_f = (int*)realloc(kol_f, sizeof(int)*(num_f + 1));
  45.         int len = strlen(str);
  46.         int r_len = strlen(razd_f);
  47.         mass_f = (char**)realloc(mass_f, sizeof(char*)*(num_f + 1));
  48.         mass_f[num_f] = NULL;
  49.         mass_f[num_f] = (char*)realloc(mass_f[num_f], sizeof(char)*(len + 1));
  50.         strcpy(mass_f[num_f], str);
  51.         int f = 1;
  52.         int r_word = 0;
  53.         int f_2 = 0;
  54.         for (int i = 0; i < len; i++)
  55.         {
  56.             for (int j = 0; j < r_len; j++)
  57.             {
  58.                 char a = str[i], b = razd_f[j];
  59.                 if (str[i] != razd_f[j] && f == 1)
  60.                 {
  61.                     f = 1;
  62.                 }
  63.                 else
  64.                 {
  65.                     f = 0;
  66.                 }
  67.             }
  68.             if (f == 1)
  69.             {
  70.                 r_word++;
  71.             }
  72.             f = 1;
  73.         }
  74.         kol_f[num_f] = r_word;
  75.         p_kol = p_kol + kol_f[num_f];
  76.         if (num_f != 0)
  77.         {
  78.             sr_kol = (p_kol - kol_f[num_f]) / (num_f);
  79.         }
  80.         if (sr_kol == kol_f[num_f])
  81.         {
  82.             f_3 = 0;
  83.         }
  84.         num_f++;
  85.     } while (f_3 == 1);
  86.     puts("Введите количество слов: ");
  87.     scanf("%d", &kol_w_f);
  88.     puts("Введите строку для вставки: ");
  89.     int i = 0;
  90.     while ((str_f[i] = getch()) != '\r')
  91.     {
  92.         i++;
  93.         str_f = (char*)realloc(str_f, (i + 1)*sizeof(char));
  94.     }
  95.     str_f[i] = '\0';
  96. }
  97.  
  98. 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)
  99. {
  100.     int flag = 0;
  101.     word_f = 0;
  102.     for (int i = 0; i < num_f; i++)
  103.     {
  104.         int len = strlen(txt_f[i]);
  105.         for (int j = 0; j < len; j++)
  106.         {
  107.             int r_len = strlen(razd_f);
  108.             for (int k = 0; (k < r_len )&& (flag = 0); k++)
  109.             {
  110.                 if (txt_f[i][j] != razd_f[k])
  111.                 {
  112.                     flag = 1;
  113.                 }
  114.             }
  115.         }
  116.         if (flag == 1)
  117.         {
  118.             word_f++;
  119.         }
  120.         if (word_f == kol_w_f)
  121.         {
  122.             razm_i_f = 0;
  123.             index_f = (int*)realloc(index_f, sizeof(int)*(razm_i_f++));
  124.             index_f[razm_i_f] = num_f;
  125.             razm_i_f++;
  126.         }
  127.     }  
  128. }
Advertisement
Add Comment
Please, Sign In to add comment