Advertisement
J3st3rs_j0k3

unwork_cw

Dec 27th, 2020
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 6.15 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <math.h>
  5. #include <ctype.h>
  6.  
  7.  
  8. void del_even(char**  first_text, int count);
  9. char ** plus(const void *a, const void* b);
  10. int del_eq_sen(char** main, char** main_update, int count);
  11.  
  12. int main(){
  13.  
  14.     char* input_words;
  15.     char** initial_txt;
  16.     char** main_upd;
  17.     char** txt_after_remove;
  18.  
  19.     initial_txt = malloc(100*sizeof(char*));
  20.     char symb;
  21.     int n;
  22.  
  23.     //выделение памяти под строку с текстом
  24.     input_words = malloc(10*sizeof(char));
  25.     int size = 100;
  26.  
  27.     int i = 0, j, counter = -1, count = 0;
  28.  
  29.     //считывание символов с клавиатуры
  30.     while((symb = getchar()) != '\n') {
  31.         input_words[i] = symb;
  32.         i++;
  33.         if (i ==  size - 1){
  34.             size = size*2;
  35.             input_words = realloc(input_words, size);
  36.         }
  37.     }
  38.  
  39.     //выделение памяти нп массив указателей (предложения)
  40.     initial_txt = malloc(100*sizeof(char*));
  41.     int size_arr = 100;
  42.  
  43.     //разделение исходной строки на предложения
  44.     for(i = 0; i < strlen(input_words); i++){
  45.         counter++;
  46.         if(input_words[i] == '.'){
  47.             initial_txt[count] = malloc(counter*sizeof(char)+10);
  48.             for(j = 0, n = i - counter; n <= i ; n++, j++){
  49.                 initial_txt[count][j] = input_words[n];
  50.             }
  51.             initial_txt = realloc(initial_txt, 100*i);
  52.             initial_txt[count][j] = '\0';
  53.             count++;
  54.             if (count == size_arr - 1){
  55.                 size_arr = size_arr*2;
  56.                 initial_txt = realloc(initial_txt, size_arr);
  57.             }
  58.             counter = -1;
  59.             i++;
  60.         }
  61.     }
  62.  
  63.     main_upd = malloc(count * sizeof(char*));
  64.     int c1 = del_eq_sen(initial_txt, main_upd, count);
  65.     initial_txt = main_upd;
  66.     for(i = 0; i < count; i ++){
  67.          printf("%s ", initial_txt[i]);
  68.     }
  69.     for(int g = 0; g < c1; g++){
  70.         printf("%s ", main_upd[g]);
  71.     }
  72.     //выделение памяти под полученный массив после работы функции del_eq_sen
  73.  
  74.     // txt_after_remove = malloc(count*sizeof(char*));
  75.  
  76.  
  77.  
  78.     // del_even(main_update, c1);
  79.  
  80.     int option;
  81.     printf("1 - Удалить все четные по счету предложения в которых четное количество слов.\n"
  82.            "2 - Отсортировать все слова в предложениях по возрастанию количества букв в верхнем регистре в слове.\n"
  83.            "3 - Заменить все слова в тексте длина которых не более 3 символов на подстроку “Less Then 3”.\n"
  84.            "4 - Найти в каждом предложении строку максимальной длины, которая начинается и заканчивается цифрой. Вывести найденные подстроки по убыванию длины подстроки.\n"
  85.            "5 - Выход из программы.\n");
  86.     // //считывание переменной, отвечающей за выбор функции, которую нужно исполнить
  87.     // scanf("%d", &option);
  88.     // switch(option){
  89.     //     case 1:
  90.  
  91.     //         break;
  92.     //     case 2: qsort(main_update, c1, sizeof(char*), plus);
  93.     //   for(int i = 0; i < c1; i++){
  94.     //       printf("%s", main_update[i]);
  95.     //   }
  96.  
  97.     //         break;
  98.     //     case 3:
  99.  
  100.     //         break;
  101.     //     case 4:
  102.  
  103.     //         break;
  104.     //     case 5:
  105.     //         printf("Программа завершена досрочно");
  106.     //         return 0;
  107.     //     default:
  108.     //         printf("Данные некорректны");
  109.  
  110.     // }
  111.  
  112.     return 0;
  113. }
  114.  
  115. //удаление одинаковых предложений
  116. int del_eq_sen(char ** main, char**main_update, int count) {
  117.     int k, z, w = 0;
  118.     char*comp_1;
  119.     char*comp_2;
  120.     for (int i = 0; i < count; i++){
  121.         k = 0;
  122.         comp_1 = main[i];
  123.         for (z = 0; z < count-1; z++) {
  124.             if (z == i)
  125.                 z++;
  126.             if (strlen(main[i]) == strlen(main[z])) {
  127.                 comp_2 = main[z];
  128.                 for (int j  = 0; j < strlen(main[i]); j++){
  129.                     comp_1[j] = (char)(tolower(comp_1[j]));
  130.                     comp_2[j] = (char)(tolower(comp_2[j]));
  131.                 }
  132.                 if (strcmp(comp_1, comp_2) == 0) {
  133.                     k++;
  134.                 }
  135.             }
  136.         }
  137.         if (i != count) {
  138.             if (k == 0)
  139.             {
  140.                 main_update[w] = main[i];
  141.                 w++;
  142.             }
  143.         }
  144.  
  145.     }
  146.     return w;
  147. }
  148.  
  149.  
  150. //функция по удалению четных предложений с четным количеством слов
  151. // void del_even(char**  first_text, int count){
  152. //     int j; int i = 1; int counter = 0;
  153. //     for(j = 1; j < count; j += 2){
  154. //         while(first_text[j][i] != '.'){
  155. //             if(first_text[j][i] == ' ' || first_text[j][i] == ','){
  156. //                 if(first_text[j][i] == ','){
  157. //                     counter++;
  158. //                     i++;
  159. //                 }
  160. //                 else{
  161. //                     counter++;
  162. //                 }
  163. //             }
  164. //             i++;
  165. //         }
  166. //         counter++;
  167. //         if(counter%2 == 0){
  168. //             free(first_text[j]);
  169. //         }
  170. //     }
  171. // }
  172.  
  173.  
  174. // char ** plus(const void *a, int count){
  175. //     char **x = (char **) a;
  176. //     counter = 0;
  177. //     //char **y = (char **) b;
  178. //     for (int i = 0; i < count; i++){
  179. //         for(int k = 0; k < strlen(array[i]); k++){
  180. //             while(array[j][k] == ' ' || array[j][k] == ", " || array[j][k] == '.'){
  181. //                 if(isalpha(array[j][k]) == TRUE && isupper(array[j][k]) == TRUE){
  182. //                     counter++;
  183. //                 }
  184. //             }
  185. //         }
  186.  
  187. //     }
  188.  
  189.  
  190. //     return
  191. // }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement