真的只用set和string就行了。
如果使用PASCAL的同学可能就要写个treap什么的了,还要用ansistring。
#include<cstdio> #include<cstring> #include<iostream> #include<string> #include<set> using namespace std; string s; string now; set<string> dict; bool is_alpha(char &c) { if (c >= 'a' && c <= 'z') return true; if (c >= 'A' && c <= 'Z') { c = c - 'A' + 'a'; return true; } return false; } int main() { dict.clear(); while(cin >> s) { now = string(""); for (int i = 0; i < s.length(); ++i) if (is_alpha(s[i])) now += s[i]; else { if (now != "") dict.insert(now); now = string(""); } if (now != "") dict.insert(now); } for (set<string>::iterator it = dict.begin(); it != dict.end(); ++it) cout << *it << " "; return 0; }