-
Notifications
You must be signed in to change notification settings - Fork 1
/
int-count.c
39 lines (34 loc) · 872 Bytes
/
int-count.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <stdlib.h>
#include <stdio.h>
#include <memory.h>
static int *numbers;
static int size = 0;
static int init_size = 1000;
static int max_num = 0;
int main(int argc, char *argv[])
{
int number, i;
size = init_size;
numbers = malloc(sizeof(int) * size);
for (i = 0; i < size; i++) {
numbers[i] = 0;
}
while (scanf("%d\n", &number) != EOF) {
if (number >= size) {
i = size;
size = number * 2;
numbers = realloc(numbers, sizeof(int) * size);
for (; i < size; i++) {
numbers[i] = 0;
}
}
if (number > max_num) {
max_num = number;
}
numbers[number]++;
}
for (i = 0; i <= max_num; i++) {
printf("%d\t%d\n", i, numbers[i]);
}
return 0;
}