参考:https://www.cnblogs.com/yjlblog/p/6947747.html
https://blog.csdn.net/hnust_taoshiqian/article/details/43448793
https://blog.csdn.net/liuke19950717/article/details/49450817
https://blog.csdn.net/fanyun_01/article/details/66967710
1 #include <iostream> 2 #include <cstdio> 3 #include <set> 4 #include <sstream> 5 using namespace std; 6 set<string> ans; 7 int main() 8 { 9 string s,temp; 10 // freopen("总结.txt","r",stdin); 11 while (cin>>s)//cin遇空格结束 ~ 12 { 13 int i; 14 for (i=0;i<s.length();i++) 15 { 16 if (isalpha(s[i])) 17 { 18 s[i]=tolower(s[i]); 19 } 20 else 21 { 22 s[i]=' '; 23 } 24 } 25 stringstream ss(s);//ss流初始化 26 while (ss>>temp)//同一个cin进来的s可能有多个单词~ 27 { 28 ans.insert(temp); 29 } 30 } 31 set<string>::iterator it; 32 for (it=ans.begin();it!=ans.end();it++) 33 { 34 cout<<*it<<endl; 35 } 36 37 return 0; 38 }