zoukankan      html  css  js  c++  java
  • 2013 gzhu acm

    题目描述:

                       Word Counting

    Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 128000/64000 KB (Java/Others)

    Problem Description

    Each year on May the graduate students are busy writing thesis, and the graduation thesis needs thousands of words. It's not a simple matter. Counting the words correctly become an interesting job.

    We all know that the thesis may include English words, numbers, punctuation marks, images, formulas, and so on.

    During the word count, we assume that English words, a string of meaningful numbers and punctuation mark is valid statistics word.

    The single character in English words or numbers can not be counted as a word.

    For example, the word "acm" count as one word instead of three words, number "2011" counted as a word. Of course, such space and carriage returns(Enter) can't be considered a word.

    Write a program to help graduates to test whether the number of words under the thesis requirement.

    Input

    There are multiple test case in input, each test case end with a single line "###", the input may contain english character, numbers, punctuation e.g. ':' , ',' , '+' , '-', and space, Enter.

    Output

    Output the number of word for each test case, and a separate line for each case.

    Sample Input

    A simple test
    ###
    Hunan University 2011 the 7th Programming Contest.
    ###
    The 5th Central South China Programming Contest.
    ###
    

    Sample Output

    3
    8
    8
    

    Source

    HNU Contest 

        这个题目要注意的是,单个的标点符号算作一个单词。

         A simple+-.ui test.    答案是:8   (simple+-.ui:simple  +  -  .  ui 共5个)

         

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstdlib>
     4 #include <cstring>
     5 #include <ctype.h>
     6 using namespace std;
     7 
     8 const int maxn = 1000 + 10;
     9 char s[maxn];
    10 
    11 int main()
    12 {
    13     int i, len, cnt = 0;
    14     while (scanf("%s", s) != EOF)
    15     {
    16           if (strcmp(s, "###") == 0)
    17           {
    18                printf("%d
    ", cnt);
    19                cnt = 0;
    20           }
    21           else{
    22                 len = strlen(s);
    23                 bool mark = false;
    24                 for (i = 0; i < len; i++)
    25                 {
    26                     if (ispunct(s[i]))
    27                     {
    28                         cnt++;
    29                         mark = false;
    30                     }
    31                     else if (!mark)
    32                     {
    33                         cnt++;
    34                         mark = true;
    35                     }
    36                 }
    37           }
    38     }
    39     return 0;
    40 }
  • 相关阅读:
    浅尝辄止——在C++中调用C#的回调函数——COM方式
    代码管理——如何连接Git Server,下载代码
    浅尝辄止——使用ActiveX装载WPF控件
    软件调试——CPU异常列表
    软件调试——IA-32 保护模式下寄存器一览
    Delphi面向对象编程
    看雪2017CTF第二题解法
    串操作指令
    MASM 重复汇编
    MASM 宏结构
  • 原文地址:https://www.cnblogs.com/windysai/p/3611486.html
Copyright © 2011-2022 走看看