现在的位置: 首页 > 综合 > 正文

UVA 494 Kindergarten Counting Game

2013年04月16日 ⁄ 综合 ⁄ 共 254字 ⁄ 字号 评论关闭

以非字母类字符作为单词结束标志要考虑的情况稍多,且很容易出错,直接统计就好。

#include<cstdio>
#include<cctype>

int main() {
    char str[500];
    while (gets(str) != NULL) {
        int cnt = 0,flag = 0;
        for (int i = 0; str[i]; i++) {
            if (isalpha(str[i])) {
                if (!flag) {
                    flag = 1;
                    cnt++;
                }
                else continue;
            }
            else flag = 0;
        }
        printf("%d\n",cnt);
    }
    return 0;
}

抱歉!评论已关闭.