SHARE
TWEET

Untitled

a guest Nov 17th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. char *scan_sentence() {
  6.     char *s = malloc(10 * sizeof(char));
  7.     int counter = 0;
  8.     int size = 10;
  9.     char current_symbol;
  10.     current_symbol = getchar();
  11.     while ((current_symbol == ' ') || (current_symbol == '\t')) {
  12.         current_symbol = getchar();
  13.     }
  14.     while ((current_symbol != '\n') && (current_symbol != ';') && (current_symbol != '.') && (current_symbol != '?') &&
  15.            (current_symbol != '!')) {
  16.         if (counter >= size - 5) {
  17.             size += 20;
  18.             s = realloc(s, size);
  19.         }
  20.         s[counter] = current_symbol;
  21.         counter++;
  22.         current_symbol = getchar();
  23.     }
  24.     s[counter++] = current_symbol;
  25.     s[counter++] = '\n';
  26.     s[counter] = '\0';
  27.     return s;
  28. }
  29.  
  30. int lucky_seven(const char *s) {
  31.     for (int i = 0; i < strlen(s); i++) {
  32.         if (s[i] == '7') {
  33.             return 1;
  34.         }
  35.     }
  36.     return 0;
  37. }
  38.  
  39. int main() {
  40.     char **arr = malloc(10 * sizeof(char *));
  41.     int counter = 0;
  42.     int size = 10;
  43.     char *s;
  44.     do {
  45.         s = scan_sentence();
  46.         if (counter == size - 1) {
  47.             size += 10;
  48.             arr = realloc(arr, size * sizeof(char *));
  49.         }
  50.         arr[counter] = s;
  51.         counter++;
  52.     } while (strcmp(s, "Dragon flew away!\n") != 0);
  53.     int count_1 = counter;
  54.     int prover = 0;
  55.     while (prover < counter) {
  56.         if (lucky_seven(arr[prover]) == 1) {
  57.             free(arr[prover]);
  58.             for (int i = prover + 1; i < counter; i++) {
  59.                 arr[i - 1] = arr[i];
  60.             }
  61.             counter--;
  62.         } else {
  63.             prover++;
  64.         }
  65.     }
  66.     for (int i = 0; i < counter; i++) {
  67.         fputs(arr[i], stdout);
  68.     }
  69.     int count_2 = counter;
  70.     printf("Количество предложений до %d и количество предложений после %d", count_1-1, count_2);
  71.     for (int i = 0; i < counter; i++) {
  72.         free(arr[i]);
  73.     }
  74.     free(arr);
  75. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top