第二期训练白银组第四题

Sum Problem

Time Limit: 1000/1000 MS
Memory Limit: 32768/32768 K

Problem Description

lily的好朋友xiaoou333最近很空,他想了一件没有什么意义的事情,就是统计一篇文章里不同单词的总数。下面你的任务是帮助xiaoou333解决这个问题。

Input

有多组数据,每组一行,每组就是一篇小文章。每篇小文章都是由小写字母和空格组成,没有标点符号,遇到#时表示输入结束。

Output

每组只输出一个整数,其单独成行,该整数代表一篇文章里不同单词的总数。

Sample Input

you are my friend

Sample Output

4

问题链接:单词数

AC通过的C语言程序如下:

#include <iostream>
#include <sstream>
#include <set>
using namespace std;

int main()
{
	string str1, str2;
	while (getline(cin, str1))
	{
		if (str1 == "#")
		{
			break;
		}
		istringstream stream(str1);
		set<string>Set;
		while(stream>>str2)
		{
			Set.insert(str2);
		}
		cout << Set.size() << endl;
	}
	
}

猜你喜欢

转载自blog.csdn.net/weixin_44003969/article/details/85009168