欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

2015年西北工业大学机试第八题

程序员文章站 2022-05-15 14:09:06
...

2015年西北工业大学机试第八题2015年西北工业大学机试第八题

直接用空格分隔,添加进set,统计个数,相同元素set只会添加一次 

#include<iostream>
#include<set>
#include<string>
using namespace std;
int main(){

	string str;
	set<string>s;
	getline(cin,str);
	int index = str.find_first_of(' ');
	while(index != -1){
		s.insert(str.substr(0,index));
		str = str.substr(index+1,str.length());
		
		index = str.find_first_of(' ');
	}
	s.insert(str);
	cout<<s.size()<<endl;
	return 0;
}