uva10815 Andy's First Dictionary(集合)

集合:和离散数学上的集合一样,就是只出现一次,里的元素已经从小到大排好了
#include
#include
#include
#include
using namespace std;
set dict;
int main()
{
    string s, buf;
    while(cin >> s) {
        for(int i= 0; i < s.length(); i++)
            if(isalpha(s[i])) s[i] = tolower(s[i]); else s[i] = ' ';//tolower是把大写换小写
        stringstream ss(s);//把普通的字符串转换成可读入set的流
        while(ss >> buf) dict.insert(buf);//这两部把更改后的字符串读入集合
    }
    //*****************************************************************
    for(set::iterator it = dict.begin(); it != dict.end(); ++it)
    //*****************************************************************
    //迭代器,便利输出,效果和数组一样
        cout << *it << "\n";
    return 0;
}

你可能感兴趣的:(UVA)