UVa 10141 Request for Proposal

Code:
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
using namespace std;
struct company
{
    string name;
    double pay;
    int num;
    friend bool operator < (company a,company b);
};
bool operator < (company a,company b)
{
    if(a.num<b.num) return true;
    else if(a.num==b.num)
        return a.pay>b.pay;
    return false;
}
int main()
{
    int n,p,cas=1;
    while(cin>>n>>p && (n!=0||p!=0))
    {
        if(cas!=1) cout<<endl;
        string line;
        getline(cin,line);
        company c[10000];
        for(int i=0; i<n; i++)
        {
            getline(cin,line);
        }
        for(int i=0; i<p; i++)
        {
            getline(cin,c[i].name);
            cin>>c[i].pay>>c[i].num;
            getline(cin,line);
            for(int j=0; j<c[i].num; j++)
            {
                getline(cin,line);
            }
        }
        stable_sort(c,c+p);
        printf("RFP #%d\n",cas++);
        if(p==1) cout<<c[p-1].name<<endl;
        else
        {
            double tmppay=c[p-1].pay;
            int tmpnum=c[p-1].num;
            for(int i=p-1; i>=0; i--)
            {
                if(c[i].num!=tmpnum || c[i].pay!=tmppay)
                {
                    cout<<c[i+1].name<<endl;
                    break;
                }
            }
        }
    }
    return 0;

}

留言

這個網誌中的熱門文章

Things a Little Bird Told Me: Confessions of the Creative Mind

UVa 12970 Alcoholic Pilots

UVa 483 Word Scramble