Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.27 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5.  
  6.  
  7. void input_func(char*** text, int* before_count, int* size){
  8.     char** text_input=(char**)malloc(10*sizeof(char*));
  9.     char c = ' ';
  10.     int count_saved=0;
  11.     int memory=1;
  12.     char* break_sent="Dragon flew away!";
  13.     int break_sent_len  = 0;
  14.     int max_heap = 10;
  15.     int max_symb_heap = 30;
  16.     int symb_index = 0;
  17.     int sent_index = 0;
  18.     while (break_sent_len!=strlen(break_sent)){
  19.        
  20.         if(memory){
  21.             if (sent_index==max_heap){
  22.                 max_heap*=2;
  23.                 text_input=realloc(text_input, max_heap*sizeof(char*));
  24.                 }
  25.             text_input[sent_index]=malloc(max_symb_heap*sizeof(char));
  26.             memory=0;  
  27.         }
  28.         c=getchar();
  29.         if (symb_index==0 && (c == ' ' || c=='\t')){
  30.             continue;}
  31.         if (c!='?'&& c!='.' && c!=';'){
  32.             if (symb_index==max_symb_heap-2){
  33.                 max_symb_heap+=5;              
  34.                 text_input[sent_index]=realloc(text_input[sent_index], max_symb_heap*sizeof(char));
  35.             }
  36.             text_input[sent_index][symb_index]=c;
  37.             symb_index++;
  38.             if (c==break_sent[break_sent_len]){
  39.                 break_sent_len++;
  40.             }else{
  41.                 break_sent_len=strlen(break_sent)+1;
  42.             }
  43.         }else{ 
  44.                 text_input[sent_index][symb_index]=c;
  45.                 text_input[sent_index][symb_index+1]='\0';
  46.                 symb_index=0;
  47.                 break_sent_len=0;
  48.                 sent_index++;  
  49.                 memory=1;
  50.                 count_saved++;
  51.                 max_symb_heap=30;
  52.            
  53.         }
  54.     }
  55. *text=text_input;
  56. *before_count=count_saved;
  57. *size=max_heap;
  58. }
  59. void clean_sent(char **text, int* after_count){
  60.     int quan_sent=*after_count;
  61.     int i = 0;
  62.     while(i<=quan_sent){
  63.         if(strlen(text[i])>2){
  64.             for(int j=0; j<strlen(text[i])-3; j++){
  65.                 if(text[i][j]=='5' && text[i][j+1]=='5' && text[i][j+2]=='5'){
  66.                     if(j==0 && (text[i][j+3]==' ' || text[i][j+3]=='.' || text[i][j+3]==';' || text[i][j+3]=='?')){
  67.                         for(int k=i; k<quan_sent; k++){
  68.                             if(strlen(text[k+1])>strlen(text[k])){
  69.                                 text[k]=(char*)realloc(text[k], (10+strlen(text[k+1]))*sizeof(char));
  70.                             }
  71.                             strcpy(text[k], text[k+1]);
  72.                         }
  73.                         quan_sent--;
  74.                         i--;
  75.                         break;
  76.                     }else{
  77.                    
  78.                         if(j==strlen(text[i])-4 && text[i][j-1]==' '){
  79.                             for(int k=i; k<quan_sent; k++){
  80.                                 if(strlen(text[k+1])>strlen(text[k])){
  81.                                     text[k]=(char*)realloc(text[k], (10+strlen(text[k+1]))*sizeof(char));
  82.                                 }
  83.                                 strcpy(text[k], text[k+1]);
  84.                             }
  85.                             quan_sent--;
  86.                             i--;
  87.                             break;
  88.                         }else{
  89.                             if(text[i][j-1]==' ' && text[i][j+3]==' '){
  90.                                 for(int k=i; k<quan_sent; k++){
  91.                                     if(strlen(text[k+1])>strlen(text[k])){
  92.                                         text[k]=(char*)realloc(text[k], (10+strlen(text[k+1]))*sizeof(char));
  93.                                     }
  94.                                     strcpy(text[k], text[k+1]);
  95.                                 }
  96.                                 quan_sent--;
  97.                                 i--;
  98.                                 break; 
  99.                             }
  100.                         }
  101.                     }          
  102.                 }
  103.             }
  104.         }
  105.     i++;   
  106.     }
  107. *after_count=quan_sent;
  108. }
  109.  
  110. int main(){
  111.     char** text;
  112.     int before_count=0;
  113.     int after_count=0;
  114.     int size;
  115.     input_func(&text, &before_count,&size);
  116.     after_count=before_count;
  117.     clean_sent(text, &after_count);
  118.     for(int i=0; i<after_count+1; i++){
  119.         printf("%s\n", text[i]);   
  120.     }
  121.     printf("Количество предложений до %d и количество предложений после %d\n", before_count, after_count);
  122.     for(int j=0; j<size; j++){
  123.         free(text[j]); 
  124.     }
  125.     free(text);
  126.     return 0;
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement