UCF Local Contest (Round 1A) Briefcases Full of Money

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;
} 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值