Friday, March 25, 2016

UVa 156 - Anagrams

#include <bits/stdc++.h>
#define LL  long long
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;

int main()
{
    string s;
    map<string,int> freq;
    map<string,string> store;

    while(cin>>s and s!="#")
    {
        string tmp = s;

        transform(ALL(s), s.begin(), ::tolower);    ///***
        sort(ALL(s));
        freq[s]++;
        store[s] = tmp;

    }

    vector <string> vs;
    map<string,int> :: iterator it;

    for(it=freq.begin(); it!=freq.end(); it++)
    {
        if(it->second == 1)     ///***
        {
            vs.push_back( store[it->first] );   ///***
        }
    }

    sort(ALL(vs));

    REP(i,SZ(vs))
    {
        cout << vs[i] << "\n";
    }
    return 0;
}

No comments:

Post a Comment