以防万一,题目原文和链接均附在文末。那么先是题目分析:
【一句话题意】
“就是统计一篇文章里不同单词的总数”(已经是一句话了。。)
【题目分析】
明显需要去重,上set,因为按行分析,又没有EOLN用,于是上istringstream。
【算法流程】
读一行塞一行干一行爱一行。。。。。
发这篇的目的其实是备忘istringstream的用法的。这道题没难点。
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h> #define each(i,n) (int i=1;i<=(n);++i) using namespace std; int main() { set<string> wordList;
string word, line; while(getline(cin, line)) {
if (line == "#") break;
istringstream stream(line);
wordList.clear();
while(stream>>word) {
wordList.insert(word);
}
cout<<wordList.size()<<endl;
}
return ; }
/*
TestData(IN)
you are my friend
#
TestData(OUT)
4
*/
题目链接:单词数(HDU 2072)
题目属性:语言练习题
相关题目:2095(随便找了一个写这里了= =)
题目原文:
【Desc】lily的好朋友xiaoou333最近很空,他想了一件没有什么意义的事情,就是统计一篇文章里不同单词的总数。下面你的任务是帮助xiaoou333解决这个问题。
【In】有多组数据,每组一行,每组就是一篇小文章。每篇小文章都是由小写字母和空格组成,没有标点符号,遇到#时表示输入结束。
【Out】每组只输出一个整数,其单独成行,该整数代表一篇文章里不同单词的总数。
【SampIn/Out】参见代码下方的注释。