#include<set>
#include<cstdio>
#include<string>
#include<iostream>
using namespace std;
int main()
{
set<string> st;
string s="";
char c;
while((c=getchar())!='#')
{
s+=c;
while(c!='\n')
{
while((c=getchar())!=' '&& c!='\n')
s+=c;
if(s.length())
st.insert(s);
s="";
}
cout<<st.size()<<endl;
st.clear();
}
return 0;
}
#include<cstdio>
#include<string>
#include<iostream>
using namespace std;
int main()
{
set<string> st;
string s="";
char c;
while((c=getchar())!='#')
{
s+=c;
while(c!='\n')
{
while((c=getchar())!=' '&& c!='\n')
s+=c;
if(s.length())
st.insert(s);
s="";
}
cout<<st.size()<<endl;
st.clear();
}
return 0;
}
C++编程中使用set数据结构进行字符串处理

本文详细介绍了在C++编程中如何利用set数据结构进行字符串处理,包括从输入中读取字符串、去除重复字符以及计算字符串集合的大小。通过实例演示了如何在循环中逐行读取输入并插入到set中,最终输出集合的大小。
345

被折叠的 条评论
为什么被折叠?



