logo资料库

华为上机考试题库.doc

第1页 / 共14页
第2页 / 共14页
第3页 / 共14页
第4页 / 共14页
第5页 / 共14页
第6页 / 共14页
第7页 / 共14页
第8页 / 共14页
资料共14页,剩余部分请下载后查看
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) view plaincopy to clipboardprint? int expert=0; int dazhong=0; int zongfen=0; int i; int number=0; 1.#include 2.#include 3.#include 4.#include 5.#define N 5 6. 7.int cal_score(int score[], int judge_type[], int n) 8. 9.{ 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. } else dazhong=dazhong+score[i]; } if(number==N) { for(i=0;i
zongfen=(int)(expert/N); expert=(int)(expert/number); dazhong=(int)(dazhong/(N-number)); zongfen=int(0.6*expert+0.4*dazhong); } return zongfen; int score[N]; int judge_type[N]; int numberlast=0; int i; printf("please input the %d score:\n",N); for(i=0;i
please input the level(1:expert,2:dazhong) 1 2 1 1 1 the last score is 85 2、给定一个数组 input[] ,如果数组长度 n 为奇数,则将数组中最大的元素放到 output[] 数 组最中间的位置,如果数组长度 n 为偶数,则将数组中最大的元素放到 output[] 数组中间 两个位置偏右的那个位置上,然后再按从大到小的顺序,依次在第一个位置的两边,按照一 左一右的顺序,依次存放剩下的数。 例如:input[] = {3, 6, 1, 9, 7} output[] = {3, 7, 9, 6, 1}; output[] = {1, 6, 8, 9, 7, 3} 8} input[] = {3, 6, 1, 9, 7, view plaincopy to clipboardprint? int i,j; 1.#include 2.#include 3.#include 4. 5. 6. 7.void sort(int input[], int n, int output[]) 8.{ 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. int k=1; int temp; int med; for(i=0;iinput[j+1]) {temp=input[j];input[j]=input[j+1];input[j+1]=temp;} if(n%2!=0) { for(i=0;i
printf("\n"); med=(n-1)/2; output[med]=input[n-1]; for(i=1;i<=med;i++) { output[med-i]=input[n-1-k]; output[med+i]=input[n-2-k]; k=k+2; } } else { 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. 49. 50. 51. } 52. 53. 54. int main() 55. { for(i=0;i
int a[6]={3,6,1,9,7,8}; int b[6]={0}; for(int i=0;i<6;i++) printf("%2d",a[i]); printf("\n"); sort(a,6,b); return 0; 56. 57. 58. 59. 60. 61. 62. 63. } 运行结果 3 6 1 9 7 8 1 3 6 7 8 9 1 6 8 9 7 3 3、操作系统任务调度问题。操作系统任务分为系统任务和用户任务两种。其中,系统任务 的优先级 < 50,用户任务的优先级 >= 50 且 <= 255。优先级大于 255 的为非法任务,应 予以剔除。现有一任务队列 task[],长度为 n,task 中的元素值表示任务的优先级,数值越 小,优先级越高。函数 scheduler 实现如下功能,将 task[] 中的任务按照系统任务、用户任 务依次存放到 system_task[] 数组和 user_task[] 数组中(数组中元素的值是任务在 task[] 数组中的下标),并且优先级高的任务排在前面,数组元素为-1 表示结束。 例如:task[] = {0, 30, 155, 1, 80, 300, 170, 40, 99} user_task[] = {4, 8, 2, 6, -1} -1} system_task[] = {0, 3, 1, 7, 函数接口 void scheduler(int task[], int n, int system_task[], int user_task[]) view plaincopy to clipboardprint? 1.#include 2.#include 3.#include 4.#include 5. 6.void scheduler1(int task[], int n, int system_task[], int user_task[])
7.{ 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. int i; int j=0; int *p,*pp,*p_user,*pp_user; int index=0; int count,count2; int min=0; int k=0; p=(int*)malloc(sizeof(int)*n); for(i=0;i
42. 43. 44. 45. 46. 47. 48. 49. 50. 51. 52. 53. 54. 55. 56. 57. 58. 59. 60. 61. 62. 63. 64. 65. 66. 67. 68. 69. 70. 71. 72. 73. 74. 75. 76. { user_task[k]=task[i]; pp_user[k]=i; k++; } count2=k; } else task[i]=task[i]; } for(i=0;i
printf("%3d",pp[p[i]]); printf("%3d\n",pp[count]); /***********************************************************/ for(i=0;i
分享到:
收藏