It is your birthday party and the six UCF programming team coaches arrive, each holding a
briefcase containing money (gift) for you. The coaches were planning to give you the six
briefcases but Dr. “O” points out that the team needs money to travel to World Contest Finals! So,
you get to choose one briefcase, i.e., you are not getting all the briefcases (sorry).
Each briefcase contains a stack of bills; each briefcase containing one of the 6 denominations $1,
$5, $10, $20, $50, $100, i.e., first briefcase contains only $1 bills, second contains only $5 bills,
third only $10 bills, fourth only $20 bills, fifth only $50 bills, and sixth only $100 bills. You, of
course, want to pick the one with the highest total amount.
The Problem:
You can randomly pick one briefcase but, as a programmer, you trust your coding skills more than
chance and decide to write a program to help you pick the briefcase with the highest amount.
The Input:
There is only one input line; it contains six integers (each integer between 1 and 1000, inclusive).
These integers represent, respectively, the number of $1, $5, $10, $20, $50, $100 bills.
The Output:
Output which briefcase to choose by printing the denomination in that briefcase (1, 5, 10, 20, 50,
100). If two or more briefcases have the highest total, pick (print) the one with fewest number of
bills among those briefcases since that one is lighter!
代码:
#include<stdio.h>
int main()
{
int a[1000],i;
int b[6]={1,5,10,20,50,100};
int max,sum;
for(i=0;i<6;i++)
{
scanf("%d",&a[i]);
}
max=0;
int temp=0;
for(i=0;i<6;i++)
{
sum=a[i]*b[i];
if(max==sum)
{
if(b[i]>temp)temp=b[i];
}
if(max<sum)
{
max=sum;temp=b[i];
}
}
printf("%d",temp);
return 0;
}