Ananagrams

 

 

#include<cstdio>
#include<iostream>
using namespace std;
#include<map>
#include<cctype>
#include<algorithm>
#include<vector>
map<string, int > mp;
string trans(const string& s)//大写转小写并排序
{
    string ans = s;
    for (int i = 0; i < ans.size(); i++)
    {
        ans[i] = tolower(ans[i]);
    }
    sort(ans.begin(), ans.end());
    return ans;
}
int main(void)
{
    vector<string> v;
    string s;
    while (cin >> s && s != "#")
    {
        v.push_back(s);
        mp[trans(s)]++;
    }
    vector<string> ans;
    for (int i = 0; i < v.size(); i++) if (mp[trans(v[i])] == 1) ans.push_back(v[i]); //如果数量为1就保存在ans中,说明这个字典中该词不能重排
    sort(ans.begin(), ans.end());
    for (int i = 0; i < ans.size(); i++) cout << ans[i] << endl;
    return 0;
}

 

posted @ 2021-01-29 16:11  loliconsk  阅读(84)  评论(0)    收藏  举报