程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> UVa——幼兒園數數游戲(494)

UVa——幼兒園數數游戲(494)

編輯:C++入門知識

494 - 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


以上是幼兒園問題的題目,其主要意思為輸入一句話,然後顯示一下這句話裡面有多少個單詞

下面是我的代碼:
#include
#include
#include

int main()
{
	int i;
	int flag,found;
	int num;
	char s;
	while(s!=EOF)
	{
		num=0;
		flag=0;
		found=0;
		while((s=getchar())!='\n'&&s!=EOF)
		{
			if(!((s>='a'&&s<='z')||(s>='A'&&s<='Z')))
			{
				flag=0;
			}
			else if(flag==0)
			{
				flag=1;
				num++;
			}
			if(num)
				found=1; 

		}
		if(found)
			printf("%d\n",num);
	}
	return 0;
}
這裡的return 0 也是至關重要的,我剛開始沒有寫,就出現了Runing Error的提示。所以初學者多加注意。

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved