Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- #include <string.h>
- #include <limits.h>
- #include <malloc.h>
- #include <stdlib.h>
- void quicksort(int* arr, int lb, int ub) {
- int i, j, m, t, mb;
- i = lb;
- j = ub;
- m = arr[(j + i) / 2];
- while (i <= j) {
- while (arr[i] < m) i++;
- while (arr[j] > m) j--;
- if (i <= j) {
- t = arr[j];
- arr[j] = arr[i];
- arr[i] = t;
- i++;
- j--;
- }
- }
- if (i < ub) quicksort(arr, i, ub);
- if (j > lb) quicksort(arr, lb, j);
- }
- int wlen[1000000];
- int main() {
- FILE *f1 = fopen("input.txt", "r");
- freopen("output.txt", "w", stdout);
- int i, j, k, count, t, min;
- char c;
- i = count = 0;
- do {
- do {
- fscanf(f1, "%c", &c);
- if (c != '\t') count++;
- } while (c != ' ' && c != '\n' && !feof(f1));
- count--;
- if (count != 0) {
- wlen[i] = count;
- i++;
- }
- count = 0;
- } while (!feof(f1));
- fclose(f1);
- quicksort(wlen, 0, i - 1);
- count = 1;
- j = 0;
- wlen[7];
- do {
- while (wlen[j] == wlen[j + 1]) {
- j++;
- count++;
- }
- if (wlen[j] != 0) printf("%d - %d", wlen[j], count);
- count = 1;
- if ((j + 1) < i && wlen[j] != 0) printf("\n");
- j++;
- } while (j < i);
- } //здесь сначала считаются длины всех слов, записываются в массив wlen в порядке встречаемости слов, далее сортировка, после которой одинаковые длины слов идут подряд(длины в порядке возрастания), далее подсчет и вывод; обрати внимание: в тестах для этой задачи(или в условии) была неточность такая, что некоторые(как минимум третий) тесты преподаватель исключил, из-за этого у тебя может неправильно работать
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement