算法之路二:刘汝佳算法竞赛入门经典:STL集合 安迪的第一个字典 UVA10851

来源:互联网 发布:美国人如何学编程的 编辑:程序博客网 时间:2024/06/07 23:37
#include<iostream>#include<string>#include<set>#include<sstream>using namespace std;set<string> dict;//string 集合 int main(){    string s,buf;    while(cin>>s)//输入字符串s     {        for(int i=0;i<s.length();i++)        if(isalpha(s[i])) s[i]=tolower(s[i]); else s[i]=' ';//si是字母把字符转换成小写         stringstream ss(s);//读取s中的单字         while(ss>>buf) dict.insert(buf);    }        for(set<string>::iterator it =dict.begin();it!=dict.end();++it)//iterator相当于指针          cout<<*it<<endl;        return 0; } 
1 0