#include<stdio.h> #include<string.h> #define ON 1 #define OFF 0 int main(void) { int spoon, chopstick, sucker, cup; spoon = chopstick = sucker = cup = OFF; while((cup=getchar())!=EOF) { if(isspace(cup)!=OFF) {//判断是否在单词外面 spoon = OFF; chopstick=OFF; } else { chopstick=ON;//在单词里面 } if(spoon==OFF&&chopstick==ON) { sucker++; spoon=ON;//初始化计数 } } printf("dan ci ge shu: %d", sucker); return 0; }
原文:http://my.oschina.net/u/1470228/blog/298353