Uva 12820 Solution

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

map<char,int>p;
vector<int>v;

void check(string s)
{
    int i;
    for(i=0;i<s.size();i++)
    {
        p[s[i]]+=1;
    }

    for(auto it=p.begin();it!=p.end();it++)
    {
       v.push_back(it->second);
    }
}

int main()
{
    int n, i, j = 1;

    while(cin >> n)
    {
        string s;
        int c = 0;
        for(i=1;i<=n;i++)
        {
            cin >> s;

            if(s.size() == 1)
                continue;

            check(s);

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

            int f = 0;

            for(int k=0;k<v.size()-1;k++)
            {
                if(v[k] == v[k+1])
                {
                    f = 1;
                    break;
                }
            }

            if(f == 0)
                c++;

            p.clear();
            v.clear();
        }
        cout << "Case " << j++ << ": " << c << endl;
    }
    return 0;
}

Comments