UVA 494 Kindergarten Counting Game

来源:互联网 发布:象棋路边残局知乎 编辑:程序博客网 时间:2024/05/16 01:24

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


#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;}


原创粉丝点击