西安市邀请赛A题 字符串基本处理

西安邀请赛A题 字符串基本处理

很抱歉,学校的OJ并不支持外网,而且还没有加上题目。。。

题意很简单,就是给一个文章,关于那个作死狗DOGE,问文章中出现了多少个DOGE,不考虑大小写。

然后就很粗暴的用toupper判断了,毫无难度。

代码如下:

/****
	*@author    Shen
	*@title     西安邀请赛A
	*/

#include <cctype>
#include <cstdio>
using namespace std;

const int maxLen = (1 << 16);
char buffer[maxLen];
int len, res;

inline bool isDOGE(int i)
{
    return  (toupper(buffer[i]) == 'D') &&
            (toupper(buffer[i + 1]) == 'O') &&
            (toupper(buffer[i + 2]) == 'G') &&
            (toupper(buffer[i + 3]) == 'E');
}

void solve()
{
    char ch = 0;
    while (~scanf("%c", &ch)) buffer[len++] = ch;
    len -= 3;
    for (int i = 0; i < len; i++)
        if (isDOGE(i))
            res++;
    printf("%d\n", res);
}

int main()
{
    solve();
    return 0;
}