Friday, October 7, 2016

UVA 10420 - List of Conquests Solution

Problem link-Click here

You have to go through MAP and SET of STL in C++. So i will recommend you to go through those terms carefully and seeing this code otherwise it's impossible to understand the following code.

an accepted code is as follows:

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

int main()
{
    int n;

    string str,h;
    map<string,int> m;
    set<string> s;
    set<string>::iterator iter;

    cin>>n;
    cin.ignore();

    while(n--)
    {
        cin>>h;
        getline(cin,str);

        m[h]++;
        s.insert(h);
    }

    for(iter=s.begin();iter!=s.end();iter++)
    {
        cout<<*iter<<" "<<m[*iter]<<endl;
    }


    return 0;
}

No comments:

Post a Comment