Sunday, December 17, 2017

UVa problem solution 10420 - List of Conquests

problem link:


Discuss: in this problem you can use map and then can sort the map.or you can just use the string first then sort the string you can use bubble sort. then just store the string in map. then just simply print the map problem will be solve. there is no tricky part in this problem.


try yourself , before see the code




#include<bits/stdc++.h>
using namespace std;
int main()
{
   map<string,int>mp;
    int n,i,j,cnt=0,flag=0,m;
    char ch[100],l[100],name[100];
    string str[2005];
    cin >>n;
    for(i=0;i<n;i++)
    {
        cin >>str[i]>>name;
        gets(l);
    }
for(i=0;i<n-1;i++)
    {
        for(j=0;j<n-1-i;j++)
        {
            if(str[j]>str[j+1])
                swap(str[j],str[j+1]);
        }
    }
for(i=0;i<n;i++)
    {
        mp[str[i]]++;
    }
    for(map<string, int>::const_iterator it = mp.begin(); it != mp.end(); ++it)
    {
        m=it->second;
                cout <<it->first<<' '<<it->second<<endl;
    }
return 0;

}

No comments:

Post a Comment