UVa : 10420 (List of Conquests)



// http://uva.onlinejudge.org/external/104/10420.html

// @BEGIN_OF_SOURCE_CODE

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <sstream>
#include <cmath>
#include <bitset>
#include <utility>
#include <set>
#define INT_MAX 2147483647
#define INT_MIN -2147483648
#define pi acos(-1.0)
#define N 1000000
using namespace std;

struct country {
    string cName;
    int frq;
} a [2000 + 10];

bool cmp (country x, country y)
{
    if ( x.cName < y.cName ) return true;
    return false;
}

int main ()
{
    int testCase;
    scanf ("%d", &testCase);
    getchar ();

    map <string, int> m;
    map <string, int>::iterator it;

    while ( testCase-- ) {
        char input [75 + 5];
        gets (input);

        char ch [75 + 5];
        char tmp [75 + 5];
        strcpy (tmp, input);

        sscanf (input, "%s", ch);

        m [ch]++;
    }

    int len = 0;
    for ( it = m.begin (); it != m.end (); it++ ) {
        a [len].cName = (*it).first;
        a [len].frq = (*it).second;
        len++;
    }

    sort (a, a + len, cmp);

    for ( int i = 0; i < len; i++ )
        cout << a [i].cName << " " << a [i].frq << endl;

	return 0;
}

// @END_OF_SOURCE_CODE

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s