Number of words Time Limit: 1000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 28734 accepted submission (s): 6898
Problem descriptionlily's good friend xiaoou333 was blank recently. He thought of a meaningless thing, that is, to count the total number of different words in an article. The following task helps xiaoou333 solve this problem.
Input contains multiple groups of data, one row in each group, and each group is a small article. Each small article is composed of lower-case letters and spaces with no punctuation marks. If it encounters "#", the input ends.
Each group outputs only one integer, which is a separate line. This integer represents the total number of different words in an article.
Sample Input
You are my friend #
Sample output
4
It looks quite simple. But I am too low on the string processing level and stuck for a long time. So I posted it to commemorate it ..
# Include <iostream> # include <map> # include <string> using namespace STD; int main () {string word; char a [1000]; int sum = 0, I; char C; Map <string, int> my; while (gets (a), a [0]! = '#') // % S skip the leading space {I = 0; while (A [I]! = 0) {word = ""; for (; A [I]! = 0; I ++) {if (a [I] = '') {I ++; break;} Word + = A [I];} If (word! = "" & My. count (Word) = 0) // possible consecutive spaces {my [word] = 1; sum ++ ;}} printf ("% d \ n ", sum); sum = 0; my. clear () ;}return 0 ;}