156 - Ananagrams

来源:互联网 发布:反编译软件 编辑:程序博客网 时间:2024/05/17 02:44
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <vector>
#include <map>
using namespace std;
typedef long long ll;


const int c = 'A' - 'a';


void deal(string &inp){
    for(int i = 0; i < inp.size(); ++i)
        if(inp[i] >= 'A' && inp[i] <= 'Z')
            inp[i] -= c;
}


int main(){
    vector<string> alstr, dalstr, out;
    string str, tstr;
    map<string, int> all;
    while(cin >> str){
        if(str[0] == '#')
        break;
        tstr = str;
        deal(tstr);
        sort(tstr.begin(), tstr.end());
        alstr .push_back(str );
        dalstr.push_back(tstr);
        if(!all.count(tstr))all[tstr] = 0;
        ++all[tstr];
    }
    for (int i = 0; i < dalstr.size(); ++i)
        if(all[dalstr[i]] == 1)
            out.push_back(alstr[i]);
    sort(out.begin(), out.end());
    for(int i = 0; i < out.size(); ++i){
        cout << out[i] <<endl;
    }
    return 0;
}
0 0
原创粉丝点击