Advertisement
bs9o

9-2

May 10th, 2018
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.87 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <string.h>
  4. #include <limits.h>
  5. #include <malloc.h>
  6. #include <stdlib.h>
  7.  
  8. void quicksort(int* arr, int lb, int ub) {
  9.     int i, j, m, t, mb;
  10.     i = lb;
  11.     j = ub;
  12.     m = arr[(j + i) / 2];
  13.     while (i <= j) {
  14.         while (arr[i] < m) i++;
  15.         while (arr[j] > m) j--;
  16.         if (i <= j) {
  17.             t = arr[j];
  18.             arr[j] = arr[i];
  19.             arr[i] = t;
  20.             i++;
  21.             j--;
  22.         }
  23.     }
  24.  
  25.     if (i < ub) quicksort(arr, i, ub);
  26.     if (j > lb) quicksort(arr, lb, j);
  27. }
  28.  
  29. int wlen[1000000];
  30.  
  31. int main() {
  32.     FILE *f1 = fopen("input.txt", "r");
  33.     freopen("output.txt", "w", stdout);
  34.     int i, j, k, count, t, min;
  35.     char c;
  36.     i = count = 0;
  37.     do {
  38.         do {
  39.             fscanf(f1, "%c", &c);
  40.             if (c != '\t') count++;
  41.         } while (c != ' ' && c != '\n' && !feof(f1));
  42.         count--;
  43.         if (count != 0) {
  44.             wlen[i] = count;
  45.             i++;
  46.         }
  47.         count = 0;
  48.     } while (!feof(f1));
  49.     fclose(f1);
  50.     quicksort(wlen, 0, i - 1);
  51.     count = 1;
  52.     j = 0;
  53.     wlen[7];
  54.     do {
  55.         while (wlen[j] == wlen[j + 1]) {
  56.             j++;
  57.             count++;
  58.         }
  59.         if (wlen[j] != 0) printf("%d - %d", wlen[j], count);
  60.         count = 1;
  61.         if ((j + 1) < i && wlen[j] != 0) printf("\n");
  62.         j++;
  63.     } while (j < i);
  64. } //здесь сначала считаются длины всех слов, записываются в массив wlen в порядке встречаемости слов, далее сортировка, после которой одинаковые длины слов идут подряд(длины в порядке возрастания), далее подсчет и вывод; обрати внимание: в тестах для этой задачи(или в условии) была неточность такая, что некоторые(как минимум третий) тесты преподаватель исключил, из-за этого у тебя может неправильно работать
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement