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<stdlib.h> #include<string.h>  int cal_score(int score[] , int judge_type[] , int n) { 	int i; 	int sum_exp = 0 , sum_nml = 0;  //sum_exp为专家评分  sum_nml大众评分 	int cnt_exp = 0 , cnt_nml = 0;  //cnt_exp为专家人数  cnt_nml为大众人数 	int ave_exp , ave_nml , aver_score;  	for(i = 0 ; i < n ; i++) 	{ 		if(judge_type[i] == 1) 		{ 			sum_exp += score[i]; 			cnt_exp++; 		} 		else 		{ 			sum_nml += score[i]; 			cnt_nml++; 		}  		ave_exp = sum_exp / cnt_exp; 		if(cnt_nml == 0) 			return ave_exp; 		ave_nml = sum_nml / cnt_nml;  		aver_score = ave_exp * 0.6 + ave_nml * 0.4;  		return aver_score; 	} }  int main() { 	int score[5] = {88 , 87 , 95 , 91 , 93}; 	int judge_type[] = {1 , 1 , 2 , 1 , 2}; 	int n = sizeof(judge_type) / sizeof(int);  	int av_score = cal_score(score , judge_type , n); 	printf("av score is %d\n" , av_score);  	system("pause"); 	return 0; }

2、给定一个数组input[],如果数组长度n为奇数,则将数组中最大的元素放到 output[]数组最中间的位置,如果数组长度n为偶数,则将数组中最大的元素放到 output[]数组中间两个位置偏右的那个位置上,然后再按从大到小的顺序,依次在第一个位置的两边,按照一左一右的顺序,依次存放剩下的数。

      例如:input[] = {3, 6, 1, 9, 7}   output[] = {3, 7, 9, 6, 1};             input[] = {3, 6, 1, 9, 7, 8}    output[] = {1, 6, 8, 9, 7, 3}

             函数接口   void sort(int input[], int n, int output[]

#include<stdio.h> #include<stdlib.h> #include<string.h> #include<math.h>  void large2small(int num[],int n) { 	int i,j,tmp; 	for(i=0 ;i<n-1;i++) 	{ 		for(j=i+1;j<n;j++) 			if(num[i]<num[j]) 			{ 				tmp = num[i]; 				num[i] = num[j]; 				num[j] = tmp; 			} 	} }  void sort(int input[], int n, int output[]) { 	int i; 	int j; 	large2small(input, n); 	if(n%2 == 1) 	{ 		 		output[(n-1)/2]= input[0]; 		j=1; 		for(i=(n-1)/2-1;i>=0;i--) 		{ 			output[i] = input[j]; 			j+=2; 		} 		j=2; 		for(i=(n-1)/2+1;i<n;i++) 		{ 			output[i] = input[j]; 			j+=2; 		}		 	} 	else if(n%2 == 0) 	{ 		output[(n)/2]= input[0]; 		j=1; 		for(i=(n)/2-1;i>=0;i--) 		{ 			output[i] = input[j]; 			j+=2; 		} 		j=2; 		for(i=(n)/2+1;i<n;i++) 		{ 			output[i] = input[j]; 			j+=2; 		}		 	}  }  int main(/*int argc, char **argv*/) { 	int input[6]={3,6,1,9,7,8}; 	int output[6]={0}; 	int i; 	sort(input, 6, output); 	for(i=0;i<6;i++) 		printf("%d ",output[i]); 	system("pause"); 	return 0; }