首页 > 代码库 > HDU 4847 陕西邀请赛A(水)

HDU 4847 陕西邀请赛A(水)

HDU 4847 Wow! Such Doge!

题目链接

题意:给定文本,求有几个doge,不区分大小写

思路:水题,直接一个个读字符每次判断即可

代码:

#include <stdio.h>
#include <string.h>

char c;
char a[5];

int main() {
    a[5] = '\0';
    int ans = 0;
    while ((c = getchar()) != EOF) {
	if (c >= 'a' && c <= 'z') c -= 32;
	a[3] = c;
	if (strcmp(a, "DOGE") == 0) ans++;
	for (int i = 0; i < 3; i++)
	    a[i] = a[i + 1];
    }
    printf("%d\n", ans);
    return 0;
}