首页 > 代码库 > UVa10815,Andy's First Dictionary, set,stringstream

UVa10815,Andy's First Dictionary, set,stringstream

题意:

输入一个文本,找出所有不同的单词,按字典序输出所有单词。



stringstream通常是用来做数据转换的
相比c库的转换,它更加安全,自动和直接

#include <sstream>

stringstream stream

stream <<value   输入

stream >>value   读取


#include <cstdio>
#include <set>
#include <string>
#include <iostream>
#include <sstream>
using namespace std;

set<string> dict;

int main()
{
    string s, buf;
    while(cin>>s){
        for(int i=0; i<s.size(); ++i){
            if(isalpha(s[i])) s[i] = tolower(s[i]);
            else s[i] = ' ';
        }
        stringstream stream;
        stream.clear();
        stream<<s;
        while(stream>>buf) dict.insert(buf);
    }
    for(set<string>::iterator it =dict.begin(); it!=dict.end(); ++it)
        cout<<*it<<endl;
    return 0;
}


UVa10815,Andy's First Dictionary, set,stringstream