# yasith/Problems

Solved Ananagrams from UVa

• Loading branch information...
yasith committed Feb 12, 2012
1 parent 1c3aab3 commit 68d73485f6939b2f9034fa5287b125f3e790f0ec
Showing with 83 additions and 0 deletions.
1. +83 −0 UVa/Ananagrams.cpp
 @@ -0,0 +1,83 @@ +// http://uva.onlinejudge.org/external/1/156.html + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define p(x) cout << #x << ":" << x << endl; + +using namespace std; + +string gen_key(string s){ + for (int i = 0; i < s.size(); i++) { + if(s[i] < 'a'){ + s[i] += 'a' - 'A'; + } + } + + char *str = new char [s.size() + 1]; + strcpy(str, s.c_str()); + + sort(str, str+s.size()); + + string sorted (str); + return sorted; +} + +int main(){ + + map > m; + + string s; + cin >> s; + + do{ + string key = gen_key(s); + + if(!m.count(key)){ + vector v; + m[key] = v; + } + m[key].push_back(s); + + cin >> s; + + }while(s.compare("#") != 0); + + vector v; + + map >::iterator it; + + for(it=m.begin(); it != m.end(); it++){ + if((*it).second.size() <= 1){ + v.push_back((*it).second[0]); + } + } + + sort(v.begin(), v.end()); + + for (int i = 0; i < v.size(); i++) { + cout << v[i] << endl; + } + + return 0; +} + +

#### 0 comments on commit `68d7348`

Please sign in to comment.