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 }
  • 相关阅读:
    oracle修改登录认证方式
    oracle设定用户密码使用时间
    oracle口令管理之允许某个用户最多尝试三次登录
    信息系统项目管理师考试大纲(组织整理)
    信息系统项目管理师考试大纲知识点汇总
    项目经理、系统架构师或技术骨干应该具备的知识
    【数据挖掘】数据挖掘工程师是做什么的?
    Java学习
    shuffle的过程分析
    Hadoop 原理总结
  • 原文地址:https://www.cnblogs.com/windysai/p/3611486.html
Copyright © 2011-2022 走看看