-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path10808.c
45 lines (38 loc) · 856 Bytes
/
10808.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
// [ 백준 ] 10808번: 알파벳 개수
#include <stdio.h>
#include <string.h>
int ASCII_LOWER_A = 'a' - 0;
int GetAlphabetIndex(char letter)
{
return letter - ASCII_LOWER_A;
}
int *CreateAlphabet()
{
int *alphabet = malloc(sizeof(int) * 26);
for (int i = 0; i < 26; i++) {
alphabet[i] = 0;
}
return alphabet;
}
int *CountAlphabet(char *word)
{
int *alphabet = CreateAlphabet();
for (int i = 0; i < strlen(word); i++) {
int index = GetAlphabetIndex(word[i]);
alphabet[index]++;
}
return alphabet;
}
void PrintAlphabetCount(char *word)
{
int *alphabet = CountAlphabet(word);
for (int i = 0; i < 26; i++) {
printf("%d ", *(alphabet + i));
}
}
int main(void)
{
char S[101];
scanf("%s", &S);
PrintAlphabetCount(S);
}