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 }
  • 相关阅读:
    E: 无法获得锁 /var/lib/dpkg/lock-frontend
    Ubuntu 18.04 更换apt源
    ubuntu18.04
    小a与“204”------数列、排序
    星际穿越
    合唱团---DP
    分苹果---暴力
    地牢逃脱----DFS搜索最优解
    下厨房---map/字符串查询
    hdu 2654 Be a hero
  • 原文地址:https://www.cnblogs.com/invisible/p/2236749.html
Copyright © 2011-2022 走看看