Tuesday, June 2, 2015

UVa - 10420 - List of Conquests

Problem Link10420 - List of Conquests

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
    string name, country;
    map <string, int> number;
    vector <string> keep;
    int test;
    cin >> test;
    getchar();
    while(test--){
        cin >> country;
        getline(cin, name);
        if(number[country] == 0)number[country]++, keep.push_back(country);
        else number[country]++;
    }
    sort(keep.begin(), keep.end());
    int sz = keep.size();
    for(int i = 0; i < sz; i++)cout << keep[i] << " " << number[keep[i]] << endl;
    return 0;
}

No comments:

Post a Comment