Problem Description
Welcome to KFC!
We love KFC, but we hate the looooooooooong queue.
Z is a programmer; he’s got an idea on the queue time computing.
Z chooses the shortest queue at first time.
He wrote a j2me program to predicate the time he have to wait in the queue. Now, he comes to KFC to test his program.
BUT, he ignored some important things to get the precise time.
Input
Input contains multiple test cases, and for each case:
First line: n B D f F, stands for n queues, time for hamburger B, time for Drink D, time for small fries f, time for big Fries F.
The next n lines: the types of each line using ABC characters.
(1<n,B,D,f,F<=100)
Output
For each case, please output the least time to wait in one line.
Sample Input
3 2 2 1 2
ABCCBACBCBAB
CBCBABBCBA
ABC
Sample Output
31
题上意思是说,会先输入五个数,分别是一共有n个队伍,一个汉堡所花的时间,一杯饮料所花的时间,小份油炸食品的时间f,大份油炸的时间F
然后会输入n行只包含ABC三个字母的字符串,A类顾客需要一个汉堡,一杯饮料和一个小份油炸食品,B类顾客需要一个汉堡,一杯饮料和一个大
份的油炸食品,C类顾客需要三个汉堡,三杯饮料喝两份大份汉堡。要求输出哪一个队列所花的时间最少。
PS:样例输出应该是3,并没有第31支队伍啊!
以下是C++代码,
#include
#include
#include
#define INF 0x3f3f3f3f
using namespace std;
int guest[3];//记录每类顾客所花的总时间
int main() {
int n;//队列数
int b,d,f,F;//各种食品所花的时间
scanf("%d%d%d%d%d",&n,&b,&d,&f,&F);
guest[0] = b + d + f;//一个A类顾客所花时间
guest[1] = b + d + F;//一个B类顾客所花时间
guest[2] = 3*b + 3*d + 2*f;//一个C类顾客所花时间
int mins = INF;//记录比较之前输入的耗时最少的队伍所花的时间,初始化为无穷大
int ans = 0;//记录之前输入的耗时最少的队伍是第几只队伍
for( int i = 1; i <= n; i++ ){
string s;
cin >> s;
int sum = 0;
for( int j = 0; j < s.length(); j++ )
sum += guest[ s[i] - 'A' ]; // 计算这一个队伍所花的总时间,存在sum中
if( sum < mins ){//比较当前队伍与之前耗时最短的队伍的耗时,如果本支队伍耗时更短则更新最少耗时队伍的耗时与编号
mins = sum;
ans = i;
}
}
printf("%d\n",ans);
return 0;
}