-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path2386.c
42 lines (37 loc) · 886 Bytes
/
2386.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
// [ 백준 ] 2386번: 도비의 영어 공부
#include <stdio.h>
#include <string.h>
char BREAK_FLAG = '#';
int MAX_SIZE = 250;
int ASCII_DIFFERENCE = 'a' - 'A';
int IsSameAlphabet(char lower, int target)
{
char upper = lower - ASCII_DIFFERENCE;
if (upper == target || lower == target ) {
return 1;
}
return 0;
}
int CountTargetAlphabet(char alphabet, char *sentence)
{
int count = 0;
for (int i = 0; i < strlen(sentence); i++) {
if (IsSameAlphabet(alphabet, sentence[i]) == 1) {
count++;
}
}
return count;
}
int main(void)
{
while (1) {
char target;
scanf(" %c", &target);
if (target == BREAK_FLAG) {
break;
}
char sentence[MAX_SIZE+1];
scanf("%[^\n]", &sentence);
printf("%c %d\n", target, CountTargetAlphabet(target, sentence));
}
}