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