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 }
  • 相关阅读:
    python 字符串前面加u,r,b的含义
    文本检测: CTPN
    ocr 识别 github 源码
    python 中写hive 脚本
    Win10 环境安装tesseract-ocr 4.00并配置环境变量
    OCR 识别原理
    pandas set_index和reset_index的用法
    整理 pandas 常用函数
    js es6 map 与 原生对象区别
    js 暂时性死区
  • 原文地址:https://www.cnblogs.com/windysai/p/3611486.html
Copyright © 2011-2022 走看看