2015年西北工业大学机试第八题
程序员文章站
2022-05-15 14:09:06
...
直接用空格分隔,添加进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;
}
上一篇: 西北工业大学机试2019
下一篇: 斐波那契数列问题