问题描述
p10815原题链接:UVaOJ 10815 - Andy's First Dictionary
相关说明:本题为《算法竞赛入门经典(第2版)》例题 5-3
解法一:集合
集合 set 的裸题,了解一下相关 STL 用法,注意像 aaa-bbb 这种文本需要当作 aaa 和 bbb 两个单词。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
#include <bits/stdc++.h> using namespace std; int main() { set<string> text; string s, buff = ""; while (cin >> s) { for (auto c : s) if (isalpha(c)) buff += tolower(c); else if (buff != "") text.insert(buff), buff = ""; if (buff != "") text.insert(buff), buff = ""; } for (auto word : text) cout << word << endl; return 0; } |
1 |
#TODO |