Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <math.h>
- #include <ctype.h>
- void del_even(char** first_text, int count);
- char ** plus(const void *a, const void* b);
- int del_eq_sen(char** main, char** main_update, int count);
- int main(){
- char* input_words;
- char** initial_txt;
- char** main_upd;
- char** txt_after_remove;
- initial_txt = malloc(100*sizeof(char*));
- char symb;
- int n;
- //выделение памяти под строку с текстом
- input_words = malloc(10*sizeof(char));
- int size = 100;
- int i = 0, j, counter = -1, count = 0;
- //считывание символов с клавиатуры
- while((symb = getchar()) != '\n') {
- input_words[i] = symb;
- i++;
- if (i == size - 1){
- size = size*2;
- input_words = realloc(input_words, size);
- }
- }
- //выделение памяти нп массив указателей (предложения)
- initial_txt = malloc(100*sizeof(char*));
- int size_arr = 100;
- //разделение исходной строки на предложения
- for(i = 0; i < strlen(input_words); i++){
- counter++;
- if(input_words[i] == '.'){
- initial_txt[count] = malloc(counter*sizeof(char)+10);
- for(j = 0, n = i - counter; n <= i ; n++, j++){
- initial_txt[count][j] = input_words[n];
- }
- initial_txt = realloc(initial_txt, 100*i);
- initial_txt[count][j] = '\0';
- count++;
- if (count == size_arr - 1){
- size_arr = size_arr*2;
- initial_txt = realloc(initial_txt, size_arr);
- }
- counter = -1;
- i++;
- }
- }
- main_upd = malloc(count * sizeof(char*));
- int c1 = del_eq_sen(initial_txt, main_upd, count);
- initial_txt = main_upd;
- for(i = 0; i < count; i ++){
- printf("%s ", initial_txt[i]);
- }
- for(int g = 0; g < c1; g++){
- printf("%s ", main_upd[g]);
- }
- //выделение памяти под полученный массив после работы функции del_eq_sen
- // txt_after_remove = malloc(count*sizeof(char*));
- // del_even(main_update, c1);
- int option;
- printf("1 - Удалить все четные по счету предложения в которых четное количество слов.\n"
- "2 - Отсортировать все слова в предложениях по возрастанию количества букв в верхнем регистре в слове.\n"
- "3 - Заменить все слова в тексте длина которых не более 3 символов на подстроку “Less Then 3”.\n"
- "4 - Найти в каждом предложении строку максимальной длины, которая начинается и заканчивается цифрой. Вывести найденные подстроки по убыванию длины подстроки.\n"
- "5 - Выход из программы.\n");
- // //считывание переменной, отвечающей за выбор функции, которую нужно исполнить
- // scanf("%d", &option);
- // switch(option){
- // case 1:
- // break;
- // case 2: qsort(main_update, c1, sizeof(char*), plus);
- // for(int i = 0; i < c1; i++){
- // printf("%s", main_update[i]);
- // }
- // break;
- // case 3:
- // break;
- // case 4:
- // break;
- // case 5:
- // printf("Программа завершена досрочно");
- // return 0;
- // default:
- // printf("Данные некорректны");
- // }
- return 0;
- }
- //удаление одинаковых предложений
- int del_eq_sen(char ** main, char**main_update, int count) {
- int k, z, w = 0;
- char*comp_1;
- char*comp_2;
- for (int i = 0; i < count; i++){
- k = 0;
- comp_1 = main[i];
- for (z = 0; z < count-1; z++) {
- if (z == i)
- z++;
- if (strlen(main[i]) == strlen(main[z])) {
- comp_2 = main[z];
- for (int j = 0; j < strlen(main[i]); j++){
- comp_1[j] = (char)(tolower(comp_1[j]));
- comp_2[j] = (char)(tolower(comp_2[j]));
- }
- if (strcmp(comp_1, comp_2) == 0) {
- k++;
- }
- }
- }
- if (i != count) {
- if (k == 0)
- {
- main_update[w] = main[i];
- w++;
- }
- }
- }
- return w;
- }
- //функция по удалению четных предложений с четным количеством слов
- // void del_even(char** first_text, int count){
- // int j; int i = 1; int counter = 0;
- // for(j = 1; j < count; j += 2){
- // while(first_text[j][i] != '.'){
- // if(first_text[j][i] == ' ' || first_text[j][i] == ','){
- // if(first_text[j][i] == ','){
- // counter++;
- // i++;
- // }
- // else{
- // counter++;
- // }
- // }
- // i++;
- // }
- // counter++;
- // if(counter%2 == 0){
- // free(first_text[j]);
- // }
- // }
- // }
- // char ** plus(const void *a, int count){
- // char **x = (char **) a;
- // counter = 0;
- // //char **y = (char **) b;
- // for (int i = 0; i < count; i++){
- // for(int k = 0; k < strlen(array[i]); k++){
- // while(array[j][k] == ' ' || array[j][k] == ", " || array[j][k] == '.'){
- // if(isalpha(array[j][k]) == TRUE && isupper(array[j][k]) == TRUE){
- // counter++;
- // }
- // }
- // }
- // }
- // return
- // }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement