HDU 2072 Word Count

Source: Internet
Author: User

Topics to note: Count the total number of different words in an article.

1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <map>5 using namespacestd;6 7 intMainvoid)8 {9     CharC//one character in the receive bufferTen     Charbuf[ -];//buffer array for temporary storage of words One     intCount//record the length of the BUF Amap<string,int> Word;//used to judge weight . -      while('#'! = (c =GetChar ())) -     { theWord.clear ();//Initialize -Count =0; -         if(' '! = c)//handling the first character -buf[count++] =C; +          while('\ n'! = (c = GetChar ()))//Handling subsequent characters -         { +             if(' '= = c && count! =0)//encountered a space and buf in the content, indicating that the word buf in reading, processing buf A             { atBuf[count] =' /'; -WORD[BUF] =1; -Count =0; -             } -             Else if(' '! = c)//Receive characters -buf[count++] =C; in             //a space is encountered, but there is no content in buf, so no processing is necessary. -         } to         if(0! = count)//count is not equal to 0, indicating that the last word is still left in buf and needs to be taken out +         { -Buf[count] =' /'; theWORD[BUF] =1; *         } $printf"%d\n", Word.size ());Panax Notoginseng     } -     return 0; the}

HDU 2072 Word Count

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.