Uva 10815 Andy's First Dictionary(字符串)

题目链接:https://vjudge.net/problem/UVA-10815

题意

找出一段文本中的所有单词,以小写形式按照字典序输出。

思路

用空白符替换文本中所有非字母字符后再次读入。

代码

#include <bits/stdc++.h>
using namespace std;
set<string> st;
int main() {
    string s;
    while (cin >> s) {
        for (char &c : s) {
            if (isalpha(c)) c = tolower(c);
            else c = ' ';
        }
        stringstream ss(s);
        string t;
        while (ss >> t) st.insert(t);
    }
    for (auto i : st) cout << i << "\n";
}

 

posted @ 2020-04-23 21:47  Kanoon  阅读(135)  评论(0编辑  收藏  举报