《2016华为校园招聘机试(成都地区)》.pdf
文本预览下载声明
2012 华为校园招聘机试(成都)
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)
#includestdio.h
#includestring.h
#includeiostream.h
#includeconio.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;iN;i++)
{
if(judge_type[i]==1)
{
expert=expert+score[i];
number++;
}
1
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;iN;i++)
scanf(%d,score[i]);
printf(please input the level(1:expert,2:dazhong)\n);
for(i=0;iN;i++)
scanf(%d,judge_type[i]);
numberlast=cal_score(score,judge_type,N);
printf(the last score is %d\n,numberlast);
return 0;
}
2
2 、给定一个数组input[] ,如果数组长度n 为奇数,则将数组中最大的元素放到 output[] 数
组最中间的位置,如果数组长度n 为偶数,则将数组中最大的元素放到 output[] 数组中间
两个位置偏右的那个位置上,然后再按从大到小的顺序,依次在第一个位置的两边,按照一
左一右的顺序,依次存放剩下的数。
例如:input[] = {3, 6, 1, 9, 7}
显示全部