UVA 494 Kindergarten Counting Game

题意为统计单词的个数

这个菜鸟竟连这都不会了,搜的大神的代码,才A

看好代码,有技巧

#include<cstdio>
#include<iostream>
#include<ctype.h>
#include<string.h>
using namespace std;
int main()
{
    char ch[550];
    int ok, cnt;
    while(gets(ch))
    {
        cnt = 0;
        ok = 1;
        for(int i = 0; ch[i]; i ++)
            if(isalpha(ch[i]))      //判断是否为大小写字母
            {
                if(ok)
                {
                    ok = 0;
                    cnt ++;
                }
            }
            else
                ok = 1;
        printf("%d\n", cnt);
    }
    return 0;
}

还有一个不开数组的

#include <stdio.h>
#include<ctype.h>
int main()
{
    char c;
    int flag = 1, count = 0;
    while ((c = getchar()) != EOF)
    {
        if (isalpha(c))
        {
            if (flag)
            {
                count++;
                flag = 0;
            }
        }
        else if (c == '\n')
        {
            printf("%d\n", count);
            count = 0;
            flag = 1;
        }
        else
            flag = 1;
    }
    return 0;
}


你可能感兴趣的:(UVA 494 Kindergarten Counting Game)