zoukankan      html  css  js  c++  java
  • 494 Kindergarten Counting Game

     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
    
    
    C++语言: Codee#23767
    01 #include <iostream>
    02 #include <cstdio>
    03 using namespace std;
    04
    05 int main()
    06 {
    07     int cnt = 0;
    08     int inword=0;
    09     for(char c; (c = getchar()) != EOF;)
    10         if(isalpha(c))
    11          inword=1;
    12          else if('\n' == c)
    13         {
    14             printf("%d\n", cnt + inword);
    15             cnt = 0;
    16             inword=0;
    17         }
    18          else if(inword)
    19          {
    20             ++cnt;
    21             inword=0;
    22          }
    23
    24     return 0;
    25 }
  • 相关阅读:
    递归神经网络 RNN 原理(上)
    递归神经网络
    队列-Python 实现
    Tableau 我常用函数整理
    代码重构(OOP)-小栗子(PyQt5)
    Python基础
    Excel 数据显示到网页
    采坑
    Python基础
    JavaScript一些对象。
  • 原文地址:https://www.cnblogs.com/invisible/p/2236749.html
Copyright © 2011-2022 走看看