-
Notifications
You must be signed in to change notification settings - Fork 0
/
1_15_gistogram.c
47 lines (45 loc) · 943 Bytes
/
1_15_gistogram.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
40
41
42
43
44
45
46
47
#include <stdio.h>
#define IN 1
#define OUT 0
int main() {
int c, i, state, len;
int gist[10];
state = OUT;
len = 0;
for (i = 0; i < 10; i++)
gist[i] = 0;
while ((c = getchar()) != EOF) {
if (c == '\t' || c == ' ' || c == '\n') {
if (state == IN) {
if (len < 10)
gist[len]++;
else
gist[0]++;
}
len = 0;
state = OUT;
}
else {
len++;
state = IN;
}
}
if (len > 0 && len < 10)
gist[len]++;
else if (len >= 10)
gist[0]++;
printf("m ");
while (gist[0] > 0) {
putchar('|');
gist[0]--;
}
putchar('\n');
for (i = 1; i < 10; i++) {
printf("%d ", i);
while (gist[i] > 0) {
putchar('|');
gist[i]--;
}
putchar('\n');
}
}