UVa 156 – Ananagrams


/******************************************
          Mobarak Hosen Shakil
        ICE, Islamic University
     ID: mhiceiuk(all), 29698(LOJ)
   E-mail: mhiceiuk @ (Gmail/Yahoo/FB)
 Blog: https://iuconvergent.wordpress.com
*******************************************/

#include<bits/stdc++.h>
using namespace std;

#define IOS             ios_base::sync_with_stdio(0);cin.tie(0)
#define LL              long long int
#define ULL             unsigned LL
#define READ(File)      freopen(File, "r", stdin)
#define WRITE(File)     freopen(File, "w", stdout)
#define FOR(i, a, b)    for(int i=a; i<b; i++)
#define REP(i, a, b)    for(int i=a; i>=b; i--)
#define PII             pair<int, int>
#define pb              push_back
#define nl              '\n'

#define dbl             printf("I'm here baby\n")

const int inf = 1<<30;
const LL INF  = 1e18;
const int MOD = 1e9+7;
const int MAXN = 300005;

/*** Custom Sorting ***/
bool Compare(const PII &x, const PII &y)
{
    if(x.first == y.first)
    {
        return x.second>y.second;
    }
    return x.first<y.first;
}

/** 3D Direction --> x, y, z **/
int dx[] = {-1,  1, 0,  0,  0,  0};
int dy[] = { 0,  0, 1, -1,  0,  0};
int dz[] = { 0,  0, 0,  0,  1, -1};
///          N,  S, E,  W,  U,  D


int main()
{
    IOS;
    string s;
    vector<string> vs;
    while(cin>>s && s!="#") vs.push_back(s);

    vector<string> ans;

    FOR(i, 0, vs.size())
    {
        if(vs[i]=="-1") continue;
        bool ok = true;

        FOR(j, i+1, vs.size())
        {
            if(vs[i].length()==vs[j].length())
            {
                string s1 = vs[i];
                string s2 = vs[j];

                FOR(k, 0, s1.length())
                {
                    if(s1[k]>='A' && s1[k]<='Z') s1[k] += 32;
                    if(s2[k]>='A' && s2[k]<='Z') s2[k] += 32;
                }

                sort(s1.begin(), s1.end());
                sort(s2.begin(), s2.end());

                if(s1==s2) {
                    ok = false;
                    vs[j] = "-1";
                }
            }
        }

        if(ok) ans.push_back(vs[i]);

    }

    sort(ans.begin(), ans.end());

    FOR(i, 0, ans.size())
    {
        cout<<ans[i]<<nl;
    }

    return 0;

}

A novice competitive programmer. Studying Bachelor of Science in Information and Communication Engineering, Islamic University, Kushtia-7003.

Tagged with: ,
Posted in UVa Problems

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Follow IU Convergent on WordPress.com
Community!
Views
  • 29,806 views