-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraph.c
66 lines (59 loc) · 1.35 KB
/
graph.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <stdio.h>
void getInput();
void paint(int *, int);
int main(){
getInput();
return 0;
}
void getInput(){
int chars[26];
int word = 1;
for(int count = 0; count < 26; count++){
chars[count] = 0;
}
char in;
char last = ' ';
while((in = getchar()) != EOF){
if(in != ' ' && in != '\n'){
chars[in - 'a']++;
} else if(in == ' ' || in == '\n'){
if(last != ' ' && last != '\n'){
word++;
}
}
last = in;
}
if(last == ' ' || last == '\n'){
word--;
}
paint(chars, word);
}
void paint(int * inputs, int word){
int max = word;
for(int count = 0; count < 26; count++){
max = max > *(inputs + count) ? max : *(inputs + count);
}
for(int count = max; count > 0; count--){
printf("%d\t", count);
for(int c = 0; c < 26; c++){
if(*(inputs + c) >= count){
putchar('*');
} else if(*(inputs + c) > 0){
putchar(' ');
}
}
if(word >= count){
putchar('*');
} else {
putchar(' ');
}
putchar('\n');
}
printf(" \t");
for(int count = 0; count < 26; count++){
if(*(inputs + count) > 0){
putchar('a' + count);
}
}
putchar('W');
}