UVA 12015 Google is Feeling Lucky






#include <bits/stdc++.h>
using namespace std;
bool compare( const pair<string,long long int>& x, const pair<string, long long int>& y )
{

    return (x.second>y.second); //descending

}
int main()
{
    long long int t,n,i,j,k,m;
    string s;
    vector<pair<string,long long int> >a;
    //freopen("12015.txt","r",stdin);
    //freopen("12015out.txt","w",stdout);
    cin>>t;
    for(i=1;i<=t;i++)
    {
        m=0;
        a.clear();
        for(j=1;j<=10;j++)
        {
            cin>>s>>n;
            if(m<n)
            {
                m=n;
            }
            a.push_back(make_pair(s,n));
        }
        stable_sort(a.begin(),a.end(),compare);
        vector<pair<string,long long int> >::iterator p;
        printf("Case #%lld:\n",i);
        for(p=a.begin();p!=a.end();p++)
        {
           if(m==p->second)
           {
               cout<<p->first<<endl;
           }
        }


    }
    return 0;




}

Download Coding Interview Book and Get More Tutorials for Coding and Interview Solution: Click Here

Download System Design Interview Book and Get More Tutorials and Interview Solution: Click Here

Do you need more Guidance or Help? Then Book 1:1 Quick Call with Me: Click Here

Share on Google Plus

About Ashadullah Shawon

I am Ashadullah Shawon. I am a Software Engineer. I studied Computer Science and Engineering (CSE) at RUET. I Like To Share Knowledge. Learn More: Click Here
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment