STL的应用
#include<map> #include<cstdio> #include<string> #include<vector> #include<cstring> #include<iostream> #include<algorithm> using namespace std; string str, s; map<string, int>mp; vector<string>V, ans; void recordStr(string s){ //cout << "here" << " " << s << endl; for(int i = 0;i < s.size();i ++) if(s[i] >= 'A' && s[i] <= 'Z') s[i] += 32; sort(s.begin(), s.end()); map<string, int>::iterator it = mp.find(s); if(it == mp.end()) mp.insert(pair<string, int>(s, 1)); else it->second ++; } bool isOnce(string s){ for(int i = 0;i < s.size();i ++) if(s[i] >= 'A' && s[i] <= 'Z') s[i] += 32; sort(s.begin(), s.end()); map<string, int>::iterator it = mp.find(s); return it->second == 1; } int main(){ //freopen("in.cpp", "r", stdin); while(getline(cin, str, ' ') && str != "#"){ //cout << str << endl; str += " "; for(int i = 0;i < str.size();i ++){ if(str[i] == ' '){ if(s.empty()) continue; recordStr(s); V.push_back(s); s.clear(); }else s.append(1, str[i]); } str.clear(); } for(int i = 0;i < V.size();i ++) if(isOnce(V[i])) ans.push_back(V[i]); sort(ans.begin(), ans.end()); for(int i = 0;i < ans.size();i ++) cout << ans[i] << endl; return 0; }