您的位置:首页 > 其它

UVA 494 Kindergarten Counting Game

2014-07-25 21:12 344 查看
题意为统计单词的个数

这个菜鸟竟连这都不会了,搜的大神的代码,才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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: