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,这导致开端为非字符的时候出现问题。

最新文章

  1. 子类继承父类时JVM报出Error:Implicit super constructor People() is undefined for default constructor. Must define an explicit constructor
  2. VC++修改电脑系统时间
  3. Code[VS] 2370 LCA 题解
  4. matlab批量合并txt文件
  5. hdu 4022 STL
  6. Behavior-Based Intelligence
  7. make clean-kernel &amp;&amp; make kernel
  8. Android权威编程指南读书笔记(1-2章)
  9. android TDD平台插入双卡时,查看允许返回发送报告的选项,去掉勾选,不起作用
  10. [Jobdu] 题目1516 : 调整数组顺序使奇数位于偶数前面
  11. WSAEventSelect IO复用模型
  12. MongoDB基础教程系列--第五篇 MongoDB 映射与限制记录
  13. es6(三):es6中函数的扩展(参数默认值、rest参数、箭头函数)
  14. OpenGL Windows 窗口程序环境搭建
  15. 通过java代码执行Linux命令查询声卡和显卡 型号
  16. 在Mac OSX上配置Appium+Android自动化测试环境
  17. SpringBoot笔记
  18. python 1-10考试
  19. python实现数组和链表的归并排序
  20. Network Mapper 嗅探工具

热门文章

  1. 52. N-Queens II(数个数)
  2. 使用Linux重定向解决nohup.out无写权限问题
  3. nw.js node-webkit系列(18)怎么对.js进行编译以防你的代码暴露出来
  4. 20145104张家明 《Java程序设计》第3周学习总结
  5. 20145311 《Java程序设计》第九周学习总结
  6. HeyWeGo小组团队项目管理
  7. Xilinx SD controller
  8. STM32组合设备实现USB转双串口
  9. python 去除不可见的控制字符
  10. pycharm同时使用python2.7版本和python3.6版本