2012届华为校园招聘上机考试题目1(9月6日下午1点场)

在网上看到华为在有的地方已经开始机试了,于是决定自己先编着试试。下面是题目和自己写的代码。 

1、选秀节目打分,分为专家评委和大众评委,score[] 数组里面存储每个评委打的分数,judge_type[] 里存储与 score[] 数组对应的评委类别,judge_type[i] == 1,表示专家评委,judge_type[i] == 2,表示大众评委,n表示评委总数。打分规则如下:专家评委和大众评委的分数先分别取一个平均分(平均分取整),然后,总分 = 专家评委平均分  * 0.6 + 大众评委 * 0.4,总分取整。如果没有大众评委,则 总分 = 专家评委平均分,总分取整。函数最终返回选手得分。

 函数接口   int cal_score(int score[], int judge_type[], int n) 

#include<stdio.h>
#include<string.h>
#include<iostream.h>
#include<conio.h>
#define N 5

int cal_score(int score[], int judge_type[], int n) 

{
	int expert=0;
    int dazhong=0;
	int zongfen=0;
	int i;
	int number=0;
	
	for(i=0;i<N;i++)
	{
		if(judge_type[i]==1)
		{
			expert=expert+score[i];
			number++;
		}
		else dazhong=dazhong+score[i];
	}
	if(number==N)
	{
		zongfen=(int)(expert/N);
	}
	else
		
    {
		expert=(int)(expert/number);
		dazhong=(int)(dazhong/(N-number));
		zongfen=int(0.6*expert+0.4*dazhong);
		
	}
	return zongfen;
	
}
int main()
{
	int score[N];
	int judge_type[N];
	int numberlast=0;
	int i;
	printf("please input the %d score:\n",N);
	for(i=0;i<N;i++)
		scanf("%d",&score[i]);
	printf("please input the level(1:expert,2:dazhong)\n");
	for(i=0;i<N;i++)
		scanf("%d",&judge_type[i]);
	numberlast=cal_score(score,judge_type,N);
	printf("the last score is %d\n",numberlast);
	return 0;
}


 

 

运行结果分析:

please input the 5 score:
90 80 87 89 91
please input the level(1:expert,2:dazhong)
1 2 1 1 1
the last score is 85
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值