Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <ctype.h>
- void input_func(char*** text, int* before_count, int* size){
- char** text_input=(char**)malloc(10*sizeof(char*));
- char c = ' ';
- int count_saved=0;
- int memory=1;
- char* break_sent="Dragon flew away!";
- int break_sent_len = 0;
- int max_heap = 10;
- int max_symb_heap = 30;
- int symb_index = 0;
- int sent_index = 0;
- while (break_sent_len!=strlen(break_sent)){
- if(memory){
- if (sent_index==max_heap){
- max_heap*=2;
- text_input=realloc(text_input, max_heap*sizeof(char*));
- }
- text_input[sent_index]=malloc(max_symb_heap*sizeof(char));
- memory=0;
- }
- c=getchar();
- if (symb_index==0 && (c == ' ' || c=='\t')){
- continue;}
- if (c!='?'&& c!='.' && c!=';'){
- if (symb_index==max_symb_heap-2){
- max_symb_heap+=5;
- text_input[sent_index]=realloc(text_input[sent_index], max_symb_heap*sizeof(char));
- }
- text_input[sent_index][symb_index]=c;
- symb_index++;
- if (c==break_sent[break_sent_len]){
- break_sent_len++;
- }else{
- break_sent_len=strlen(break_sent)+1;
- }
- }else{
- text_input[sent_index][symb_index]=c;
- text_input[sent_index][symb_index+1]='\0';
- symb_index=0;
- break_sent_len=0;
- sent_index++;
- memory=1;
- count_saved++;
- max_symb_heap=30;
- }
- }
- *text=text_input;
- *before_count=count_saved;
- *size=max_heap;
- }
- void clean_sent(char **text, int* after_count){
- int quan_sent=*after_count;
- int i = 0;
- while(i<=quan_sent){
- if(strlen(text[i])>2){
- for(int j=0; j<strlen(text[i])-3; j++){
- if(text[i][j]=='5' && text[i][j+1]=='5' && text[i][j+2]=='5'){
- if(j==0 && (text[i][j+3]==' ' || text[i][j+3]=='.' || text[i][j+3]==';' || text[i][j+3]=='?')){
- for(int k=i; k<quan_sent; k++){
- if(strlen(text[k+1])>strlen(text[k])){
- text[k]=(char*)realloc(text[k], (10+strlen(text[k+1]))*sizeof(char));
- }
- strcpy(text[k], text[k+1]);
- }
- quan_sent--;
- i--;
- break;
- }else{
- if(j==strlen(text[i])-4 && text[i][j-1]==' '){
- for(int k=i; k<quan_sent; k++){
- if(strlen(text[k+1])>strlen(text[k])){
- text[k]=(char*)realloc(text[k], (10+strlen(text[k+1]))*sizeof(char));
- }
- strcpy(text[k], text[k+1]);
- }
- quan_sent--;
- i--;
- break;
- }else{
- if(text[i][j-1]==' ' && text[i][j+3]==' '){
- for(int k=i; k<quan_sent; k++){
- if(strlen(text[k+1])>strlen(text[k])){
- text[k]=(char*)realloc(text[k], (10+strlen(text[k+1]))*sizeof(char));
- }
- strcpy(text[k], text[k+1]);
- }
- quan_sent--;
- i--;
- break;
- }
- }
- }
- }
- }
- }
- i++;
- }
- *after_count=quan_sent;
- }
- int main(){
- char** text;
- int before_count=0;
- int after_count=0;
- int size;
- input_func(&text, &before_count,&size);
- after_count=before_count;
- clean_sent(text, &after_count);
- for(int i=0; i<after_count+1; i++){
- printf("%s\n", text[i]);
- }
- printf("Количество предложений до %d и количество предложений после %d\n", before_count, after_count);
- for(int j=0; j<size; j++){
- free(text[j]);
- }
- free(text);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement