代码
set (不允许元素重复)
- #include <iostream>
- #include <set>
- #include <string>
- #include <sstream> // istringstrem stream() 的头文件!
- using namespace std;
- int main()
- {
- string art;
- while(getline(cin,art) && art != "#") // 整行整行的输入
- {
- //对象用来把一个已定字符串中的以空格隔开的内容提取出来
- istringstream stream(art);
- string word;
- set<string> map;
- while(stream >>word) // 把提取出来的单词赋给 word
- {
- map.insert(word);
- }
- cout <<map.size() <<endl;
- }
- return 0;
- }