Kindergarten Counting Game 

Everybody sit down in a circle. Ok. Listen to me carefully.

``Woooooo, you scwewy wabbit!''

Now, could someone tell me how many words I just said?

Input and Output

Input to your program will consist of a series of lines, each line containing multiple words (at least one). A ``word'' is defined as a consecutive sequence of letters (upper and/or lower case).

Your program should output a word count for each line of input. Each word count should be printed on a separate line.

Sample Input

Meep Meep!
I tot I taw a putty tat.
I did! I did! I did taw a putty tat.
Shsssssssssh ... I am hunting wabbits. Heh Heh Heh Heh ...

Sample Output

2
7
10
9 --------------------------------------------------------------------------------------------
本题主要是判断一行字符串中有多少个word。判断方法为,一个字母开头到不是字母的字符结束为一个词。注意:也许一行的开头就是非字符
 #include<stdio.h>
#include<string.h>
#include<ctype.h>
#define MAXN 1000
char buf[MAXN];
int main(){
int len,j,sum;
char oldch;
while(fgets(buf,MAXN,stdin) != NULL){
len = strlen(buf);
sum = ;
oldch = buf[];
for(j = ; j < len; j++){
if(isalpha(oldch) > && isalpha(buf[j]) == ){
sum++;
}
oldch = buf[j];
}
printf("%d\n",sum);
}
}

刚开始犯的错误为:认为开端一定为字符,判断就使用了isalpha(j)  == 0 && isalpha(j-1) > 0,这导致开端为非字符的时候出现问题。

494 - Kindergarten Counting Game的更多相关文章

  1. UVA 494 Kindergarten Counting Game

    题目大意:输入一个字字符串,输出该字符串中所包含的"word"个数,其中"word"是指连续的字母(大小写均可) 题目思路:其实这是道水题,不过我考虑的时候,太 ...

  2. UVA 494 Kindergarten Counting Game map

    Everybody sit down in a circle. Ok. Listen to me carefully.“Woooooo, you scwewy wabbit!”Now, could s ...

  3. Kindergarten Counting Game - UVa494

    欢迎访问我的新博客:http://www.milkcu.com/blog/ 原文地址:http://www.milkcu.com/blog/archives/uva494.html 题目描述  Kin ...

  4. uva494 Kindergarten Counting Game

    #include<bits/stdc++.h>using namespace std;int main(){ int n=0; char a; int flag=1; while((sca ...

  5. UVA_494:Kindergarten Counting Game

    Language: C++ 4.8.2 #include<stdio.h> #include<ctype.h> int main(void) { int ch; int wor ...

  6. UVA题目分类

    题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...

  7. 【索引】Volume 0. Getting Started

    AOAPC I: Beginning Algorithm Contests (Rujia Liu) Volume 0. Getting Started 10055 - Hashmat the Brav ...

  8. UVa OJ 494

     Kindergarten Counting Game  Everybody sit down in a circle. Ok. Listen to me carefully. ``Woooooo, ...

  9. Zerojudge解题经验交流

    题号:a001: 哈囉 背景知识:输出语句,while not eof 题号:a002: 簡易加法 背景知识:输出语句,while not eof,加法运算 题号:a003: 兩光法師占卜術 背景知识 ...

随机推荐

  1. http之post和get请求的区别

    GET请求 GET /books/?sex=man&name=Professional HTTP/1.1 Host: www.wrox.com User-Agent: Mozilla/5.0 ...

  2. ACM ICPC, JUST Collegiate Programming Contest (2018) Solution

    A:Zero Array 题意:两种操作, 1 p v  将第p个位置的值改成v  2  查询最少的操作数使得所有数都变为0  操作为可以从原序列中选一个非0的数使得所有非0的数减去它,并且所有数不能 ...

  3. poj1106 Transmitters

    地址:http://poj.org/problem?id=1106 题目: Transmitters Time Limit: 1000MS   Memory Limit: 10000K Total S ...

  4. MapReduce 过程详解 (用WordCount作为例子)

    本文转自 http://www.cnblogs.com/npumenglei/ .... 先创建两个文本文件, 作为我们例子的输入: File 1 内容: My name is Tony My com ...

  5. Python3.x:requests的用法

    Python3.x:requests的用法 1,requests 比 urllib.request 容错能力更强: 2,通常用法: (1).认证.状态码.header.编码.json r = requ ...

  6. GreenOpenPaint的实现(六)图片的保存和打开

    如果只是直接的图片保存和打开,是没有很多内容的.但是我这里,将EXIF的信息融入其中,使得图像处理的结果能够保存下来.这样就非常有价值意义了. 所有的操作都放在DOC中进行处理. 我之前已经对EXIF ...

  7. 解决Tomcat端口被占用 及 启用失败等其它错误整理册

    使用管理员模式启动命令行工具. netstat -ano|findstr 获取了pid号 taskkill /pid /f 其中6428为pid号,可能有不同. -------- 有时遇到其它问题可以 ...

  8. 【转】集群/分布式环境下5种session处理策略

    转载至:http://blog.csdn.net/u010028869/article/details/50773174 在搭建完集群环境后,不得不考虑的一个问题就是用户访问产生的session如何处 ...

  9. Anaconda中常用的用法

    Anaconda中常用的用法 conda 是开源包(packages)和虚拟环境(environment)的管理系统. packages 管理: 可以使用 conda 来安装.更新 .卸载工具包 ,并 ...

  10. Python学习札记(二十八) 模块1

    参考:模块 NOTE 1.模块:一个.py文件称为一个模块. 2.代码模块化的意义:a.提升程序的可维护性 b.不用重复造轮子 3.避免模块冲突,解决方法:引入了按目录来组织模块的方法,称为包(Pac ...