竹園論壇
標題:
10141 - Request for Proposal
[打印本頁]
作者:
jd3
時間:
2014-5-18 21:31
標題:
10141 - Request for Proposal
本帖最後由 jd3 於 2014-5-18 22:46 編輯
英文原題:
http://uva.onlinejudge.org/external/101/10141.html
中文翻譯:
http://luckycat.kshs.kh.edu.tw/homework/q10141.htm
==========================================================
注意事項:所有名稱,包含廠商及服務,都可能有空格,請小心讀取
使用getline, gets, ......時,注意前一行的換行字元在scanf後不會消失,可以先用getchar讀掉
==========================================================
解法:因為廠商提供的服務有多少個已經直接講明了,且沒有不需要的服務
所以直接開struct (class)多載 operator 用直接比較更新答案或開陣列下去sort找頭或尾
======
CODE :
======
/*
UVA 10141
AC 9ms
*/
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
struct Prop
{
char name[82];
double cost;
int mark;
Prop(){mark = -1;};
};
inline bool operator < (const Prop &p1, const Prop &p2)
{
if(p1.mark != p2.mark)
return p1.mark < p2.mark;
return p1.cost > p2.cost;
}
int n,p;
int r;
string order[1024];
Prop prop;
string item[1024];
int main()
{
for(int t = 1 ; ; t++)
{
Prop ans;
scanf("%d%d", &n, &p);
if(n==0 && p==0)
return 0;
getchar();
for(int i = 0 ; i < n ; i++)
getline(cin, order[0]);
for(int i = 0 ; i < p ; i++)
{
gets(prop.name);
scanf("%lf%d", &prop.cost, &prop.mark);
getchar();
for(int j = 0 ; j < prop.mark ; j++)
getline(cin, item[j]);
if(ans < prop)
ans = prop;
}
if(t > 1)
putchar('\n');
printf("RFP #%d\n",t);
printf("%s\n",ans.name);
}
return 0;
}
(( 參考網路sort版:
http://hoyusun.blogspot.tw/2012/ ... t-for-proposal.html
歡迎光臨 竹園論壇 (http://forum.tfcis.org/)
Powered by Discuz! X3.2