当前位置:编程学习 > JAVA >>

2012届华为校园招聘上机考试题目(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) 

      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[])

      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}    system_task[] = {0, 3, 1, 7, -1}    user_task[] = {4, 8, 2, 6, -1}

             函数接口    void scheduler(int task[], int n, int system_task[], int user_task[]) --------------------编程问答-------------------- 这个绝对要顶,谢谢楼主分享!!! --------------------编程问答-------------------- 这应该是C的程序啊,怎么放到java来了
不过思路差不多的,随便写写了

Q1
int cal_score(int score[], int judge_type[], int n) {
    double v1 = 0;
    double v2 = 0;
    int n1 = 0;
    int n2 = 0;
    for (int i=0; i<n; i++) {
        if (judge_type[i] == 1) {
            v1 += score[i];
            n1++;
        } else {
            v2 += score[i];
            n2++;
        }
    }
    if (n2 == 0) {
        return (int)(v1/n1);
    } else {
        return (int)(0.6*v1/n1 + 0.4*v2/n2);
    }
}

Q2
void sort(int input[], int n, int output[]) {
    int center = (n%2 == 0) ? n/2 + 1 : n/2;
    for (int i=0; i<n; i++) {
        for (int j=1, k=0; j<n-i; j++) {
            if (input[j] > input[j-1]) {
                k = input[j];
                input[j] = input[j-1];
                input[j-1] = k;
            }
        }
    }
    output[center] = input[0];
    for (int i=1, j=center-1, k=center+1; i<n; i+=2) {
        if (j >= 0) output[j--] = input[i];
        if (k < n) output[k++] = input[i+1];
    }
}

Q3
void scheduler(int task[], int n, int system_task[], int user_task[]) {
    int n1 = 0;
    int n2 = 0;
    for (int i=0, j=0, k=0; i<n; i++) {
        if (task[i] < 50) {
            system_task[j++] = i;
            n1++;
        } else {
            user_task[k++] = i;
            n2++;
        }
    }
    for (int i=0; i<n1; i++) {
        for (int j=1, k=0; j<n1-i; j++) {
            if (task[system_task[j]] < task[system_task[j-1]]) {
                k = system_task[j];
                system_task[j] = system_task[j-1];
                system_task[j-1] = k;
            }
        }
    }
    for (int i=0; i<n2; i++) {
        for (int j=1, k=0; j<n2-i; j++) {
            if (task[user_task[j]] < task[user_task[j-1]]) {
                k = user_task[j];
                user_task[j] = user_task[j-1];
                user_task[j-1] = k;
            }
        }
        if (task[user_task[n2-i]] > 255) {user_task[n2-i] = -1;}
    }
}
--------------------编程问答-------------------- if (task[user_task[n2-i]] > 255) {user_task[n2-i] = -1;}
改成
if (task[user_task[n2-i-1]] > 255) {user_task[n2-i-1] = -1;}
--------------------编程问答-------------------- mark. --------------------编程问答-------------------- 路过,学习了 --------------------编程问答-------------------- mark --------------------编程问答-------------------- X    fd   --------------------编程问答-------------------- 真的是不要求效率么。。。 那是不是有点简单了 连我都能看懂 --------------------编程问答-------------------- 囧,我看着也是c,不要求效率是没什么难度的 --------------------编程问答-------------------- q3一边分类一边使用插入排序是不是会好一点啊。 --------------------编程问答-------------------- 顶一个,支持楼主 --------------------编程问答-------------------- 华为校园招聘要上机。????????????? --------------------编程问答--------------------
引用 8 楼 caishenfans 的回复:
真的是不要求效率么。。。 那是不是有点简单了 连我都能看懂


今天去科大讯飞打酱油   题目比这个 还~~~ --------------------编程问答-------------------- 顶一个 --------------------编程问答--------------------
引用 10 楼 yueyuan_692 的回复:
q3一边分类一边使用插入排序是不是会好一点啊。

最好还是分开,大循环的处理尽量简单
如果是一边分类一边插入排序,就会造成大循环套小循环(插入排序要移动元素)
所以性能上未必见得好
--------------------编程问答-------------------- 见识了,谢谢。 --------------------编程问答-------------------- 必须顶! --------------------编程问答-------------------- 路过 ,,,, --------------------编程问答--------------------
引用 2 楼 qybao 的回复:
这应该是C的程序啊,怎么放到java来了
不过思路差不多的,随便写写了

C/C++ code
Q1
int cal_score(int score[], int judge_type[], int n) {
    double v1 = 0;
    double v2 = 0;
    int n1 = 0;
    int n2 = 0;
    for (int i=0; i<……

第二题 中的center应该就是n/2, 不用分情况了吧 --------------------编程问答-------------------- 楼主是在哪里上机的啊?怎么和成都的一位仁兄题目一样的啊! --------------------编程问答-------------------- 同感。没效率要求的话,是有点简单了 --------------------编程问答--------------------
引用 19 楼 hudesign 的回复:
引用 2 楼 qybao 的回复:

这应该是C的程序啊,怎么放到java来了
不过思路差不多的,随便写写了

C/C++ code
Q1
int cal_score(int score[], int judge_type[], int n) {
double v1 = 0;
double v2 = 0;
int n1 = 0;
int n2 = 0;
for (int ……


宝哥第二题的拿中间数下标确实不用分情况,会自动去余的~~

话说回来第二题还是只能先排input再插入output么,一次便利能有好方法不 --------------------编程问答-------------------- 这也。。。貌似简单了点吧。。。可信度高吗? --------------------编程问答-------------------- 嘿嘿i、 --------------------编程问答-------------------- 但是如果2个人都做出来了,但只要1个人的话,还是要看性能的吧。 --------------------编程问答--------------------
引用 25 楼 softroad 的回复:
但是如果2个人都做出来了,但只要1个人的话,还是要看性能的吧。


靠、 速度 优先 啊  --------------------编程问答-------------------- 经过,留名一下,嘿嘿! --------------------编程问答-------------------- #6楼 得分:0回复于:2011-09-20 15:23:11
mark 
  --------------------编程问答--------------------
引用 22 楼 lacus87 的回复:
宝哥第二题的拿中间数下标确实不用分情况,会自动去余的~~

话说回来第二题还是只能先排input再插入output么,一次便利能有好方法不

确实是,中间数不用分情况,直接 int center = n/2; 就可以了,看题目简单也没细想那么多了
第二题一次遍历也不是不可以

Q2
void sort(int input[], int n, int output[]) {
    int center = n/2;
    int max = 0x10000000; //int最小值
    int index = 0;
    for (int i=0; i<n; i++) { //每次查找下一个最大值
        for (int j=0; j<n; j++) { //找到下一个最大值
            if (input[j] > max) {
                max = input[j];
                index = j;
            }
        }
        output[center + (i%2==0 ? 1 : -1)*(i+1)/2] = max; //排列最大值
        input[index] = max = 0x10000000; //把最大值置成最小
    }
}
--------------------编程问答-------------------- 阿宝V5 --------------------编程问答-------------------- 路过
--------------------编程问答-------------------- 学习了 --------------------编程问答-------------------- 过来学习下 --------------------编程问答-------------------- 第三题用的是冒泡吧 --------------------编程问答-------------------- 用快速排序 时间复杂度 不至于 o(n2) --------------------编程问答-------------------- 学习下,看看都是些什么题目 --------------------编程问答-------------------- 不错呀!顶一下… --------------------编程问答-------------------- 顶一下。。。 --------------------编程问答-------------------- 毕竟是刚毕业的大学生,要求不能太高啊 --------------------编程问答-------------------- mark --------------------编程问答-------------------- 留个名 以后看 --------------------编程问答-------------------- mark 一下,哎,有技术一点点多了--- 至少对于我来说,好久没酱紫考虑下逻辑了 --------------------编程问答-------------------- 学习啦 --------------------编程问答-------------------- 留名,以后再细读 --------------------编程问答-------------------- piaolai学习
--------------------编程问答-------------------- 支持楼主  学习学习 --------------------编程问答-------------------- 以后在里面多多的学习啦。。 --------------------编程问答-------------------- 改天过来做 --------------------编程问答-------------------- 好东西啊 --------------------编程问答-------------------- mark  ........................... --------------------编程问答-------------------- 学习    马上要找工作了 --------------------编程问答-------------------- mark 有空看看! --------------------编程问答-------------------- 那评判标准是什么?每个人都做出来咋办? --------------------编程问答-------------------- 那评判标准是什么?每个人都做出来咋办? --------------------编程问答-------------------- 那评判标准是什么?每个人都做出来咋办? --------------------编程问答-------------------- 受教了! --------------------编程问答-------------------- 其实前面两个是对数据结构的考察,最后一个是线程。
第一题是C中指针的运用,第二题是是数据查找的一个反向运用,第三题是对线程调度和死锁的处理。 --------------------编程问答--------------------
引用 55 楼 jiyanchang 的回复:
那评判标准是什么?每个人都做出来咋办?


比得 就是 速度、和 合理性  --------------------编程问答-------------------- 这是我的博文 地址:http://blog.csdn.net/zs312979674/article/details/6816375 

大家互相学习学习下子 --------------------编程问答--------------------
引用 57 楼 l194wt 的回复:
其实前面两个是对数据结构的考察,最后一个是线程。
第一题是C中指针的运用,第二题是是数据查找的一个反向运用,第三题是对线程调度和死锁的处理。


任何语言都受用  --------------------编程问答-------------------- 今天的华为上机题目,1题:

输入百分制成绩,转化为对应的5个等级,90以上A,80-90为B。。。以下省略。。。你们懂的。、。。。。。。。。。。。。。。。。。。。。。。。。。 --------------------编程问答--------------------
引用 61 楼 dxx1988 的回复:
今天的华为上机题目,1题:

输入百分制成绩,转化为对应的5个等级,90以上A,80-90为B。。。以下省略。。。你们懂的。、。。。。。。。。。。。。。。。。。。。。。。。。。


呵呵 --------------------编程问答-------------------- --------------------编程问答-------------------- 我不会  ...... --------------------编程问答-------------------- 哈哈,来练练手

package com.algorithm;

public class HaweiQuestion {
public static void main(String[] args) {
HaweiQuestion q = new HaweiQuestion();
int[] input = {3, 6, 1, 9, 7, 8}; 
int[] output = new int[input.length];
q.sort(input, input.length, output);
for(int i=0;i<input.length;i++){
System.out.print(output[i]+" ");
}
System.out.println();
int[] task = {0, 30, 155, 1, 80, 300, 170, 40, 99};
int[] system_task = new int[task.length];
int[] user_task = new int[task.length];
q.scheduler(task, task.length, system_task, user_task);
}

/**
 * 选秀节目打分,分为专家评委和大众评委,score[] 数组里面存储每个评委打的分数,
 * judge_type[] 里存储与 score[] 数组对应的评委类别,judge_type[i] == 1,表示专家评委,
 * judge_type[i] == 2,表示大众评委,n表示评委总数。
 * 打分规则如下:专家评委和大众评委的分数先分别取一个平均分(平均分取整),
 * 然后,总分 = 专家评委平均分 * 0.6 + 大众评委 * 0.4,总分取整。如果没有大众评委,
 * 则 总分 = 专家评委平均分,总分取整。函数最终返回选手得分。
 */
public int cal_score(int score[], int judge_type[], int n)  {
int proNum=0;
int peoNum=0;
int total=0;
int peoCount=0;
for(int i=0;i<n;i++){
if(judge_type[i]==1){
proNum += score[i];
}else{
peoNum += score[i];
peoCount++;
}
}
if(peoCount!=0)
total = (int)(proNum * 0.6 + peoNum * 0.4);
else
total = proNum / n ;
return total;
}


/**
 * 给定一个数组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}
 */
 public void sort(int input[], int n, int output[]){
 //首先按从大到小的顺序排列input
 for(int i=0; i < n;i++){
 for(int j = i;j > 0;j--){
 if(input[j] > input[j-1]){ //大数上浮
 swap(input,j,j-1);
 }
 }
 }

int count = 0;
for (int i = n / 2, j = n / 2; i >= 0 && j < n; i--, j++) {
if (i == j) {
output[i] = input[count++];
} else {
output[i] = input[count++];
output[j] = input[count++];
}
}
if(n%2 == 0){ //偶数还有一个值
output[0] = input[count];
}
 
 }

private void swap(int[] input, int j, int i) {
int temp = input[j];
input[j] = input[j-1];
input[j-1] = temp;

}


/**
 * 操作系统任务调度问题。操作系统任务分为系统任务和用户任务两种。
 * 其中,系统任务的优先级 < 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} 
     * system_task[] = {0, 3, 1, 7, -1} user_task[] = {4, 8, 2, 6, -1}
 */
public void scheduler(int task[], int n, int system_task[], int user_task[]){
int[] indexs = new int[n]; //用来保存下标
for(int i=0;i<n;i++){ //初始化
indexs[i] = i ;
}
//按从小到大的顺序排列task
 for(int i=0; i < n;i++){
 for(int j = i;j > 0;j--){
 if(task[j] < task[j-1]){ //小数上浮,相等不交换
 swap(task,j,j-1);
 swap(indexs,j,j-1); //同时交换下标
 }
 }
 }
 int sysPoint = 0;
 int userPoint = 1;
 for(int i=0;i<n;i++){
 if(task[i] < 50){
 system_task[sysPoint++] = indexs[i];
 }else if(task[i]<=255){
 user_task[userPoint++] = indexs[i];
 }else{
 //do nothing
 }
 }
}
}

--------------------编程问答-------------------- 顶一个 --------------------编程问答--------------------
引用 65 楼 zhouyunan2010 的回复:
哈哈,来练练手
Java code

package com.algorithm;

public class HaweiQuestion {
    public static void main(String[] args) {
        HaweiQuestion q = new HaweiQuestion();
        int[] input = {3, 6, 1, 9……


嘿嘿  --------------------编程问答-------------------- 呃,Jave的 --------------------编程问答-------------------- 共勉~! --------------------编程问答-------------------- 华为校园招聘又开始啦啊 --------------------编程问答-------------------- 问题2:

//-------------------------------------------------------------
void sort(int input[], int n, int output[])
{
int i,j,temp;
int a=0,b=1;

for (i=n-1;i>=0;i--)
{
for (j=0;j<i;j++)
{
if (input[i]<input[j])
{
temp=input[i];
input[i]=input[j];
input[j]=temp;
}
}

if ((n-1-i)%2==0)
{
output[n/2+a]=input[i];
printf("output[%d]=%d\n",n/2+a,output[n/2+a]);
a++;
}
else
{
output[n/2-b]=input[i];
printf("output[%d]=%d\n",n/2-b,output[n/2-b]);
b++;
}
}
}
//-------------------------------------------------------------
--------------------编程问答-------------------- 问题一:

//-------------------------------------------------------------
int cal_score(int score[], int judge_type[], int n) 
{
int i=0,a=0,b=0; //一定要初始化
int a_score=0,b_score=0,last_score=0; //一定要初始化
for (i=0;i<n;i++)
{
if (judge_type[i]==1)
{
a_score+=score[i];
a++;
}
else
{
b_score+=score[i];
b++;
}
}
a_score/=a;
b_score/=b;
if (b==0)
{
last_score=a_score;
}
else
{
last_score=a_score*0.6+b_score*0.4;
}

return last_score;

}

//-------------------------------------------------------------
--------------------编程问答-------------------- 学习了 --------------------编程问答--------------------

 int max = 0x10000000; //int最小值


?这个不是啊 --------------------编程问答-------------------- 求其他公司的面试题,提前适应,谢谢 --------------------编程问答-------------------- 请问结论从何而来?题目并没有要求是C题目吧
引用 2 楼 qybao 的回复:
这应该是C的程序啊,怎么放到java来了
不过思路差不多的,随便写写了

C/C++ code
Q1
int cal_score(int score[], int judge_type[], int n) {
    double v1 = 0;
    double v2 = 0;
    int n1 = 0;
    int n2 = 0;
    for (int i=0; i<……
--------------------编程问答--------------------
引用 19 楼 hudesign 的回复:
引用 2 楼 qybao 的回复:

这应该是C的程序啊,怎么放到java来了
不过思路差不多的,随便写写了

C/C++ code
Q1
int cal_score(int score[], int judge_type[], int n) {
double v1 = 0;
double v2 = 0;
int n1 = 0;
int n2 = 0;
for (int i……


应该都不用考虑情况,都是n/2+1...... --------------------编程问答-------------------- 各位同仁,说句题外话
华为上班很辛苦的,周六上班不算加班,平时基本上也是10小时工作
能撑下来3年就算不错了

要去的话,一定要想清楚呀 --------------------编程问答--------------------
引用 78 楼 bigheadsheep 的回复:
各位同仁,说句题外话
华为上班很辛苦的,周六上班不算加班,平时基本上也是10小时工作
能撑下来3年就算不错了

要去的话,一定要想清楚呀

是的,  华为=加班   这个是恒等 --------------------编程问答-------------------- 很好。。。顶!!! --------------------编程问答-------------------- MARK --------------------编程问答-------------------- mark --------------------编程问答-------------------- 华为-----学习  了
--------------------编程问答-------------------- int cal_score(int score[], int judge_type[], int n) 
{
        float sum1 = 0,sum2=0,lastscore,a_sum,b_sum;
         int i = 0,j=0;
         
       if(judge_type[i] == 1)
      {
              sum =score[i]+sum;
                 i++;
              a_sum=sum/i-1;
                
      }
      if(judge_type==2)
     {

      sum2 = sum2 +score[j];
               j++;
           b_sum=sum2/j-1;
     }
      lastscore=(a_sum1*0.6+b_sum*0.4);

} --------------------编程问答-------------------- void sort(int input[], int n, int output[])
{
   int temp;
   int i,j,k;
   for(i = 0; i < n-1; i++) 
   {
      for(j = i+1;j< n ;j++)
         {
          if(input[i]>input[j])
           {
             temp = input[i];
             input[i] =input[j];
             input[j]=temp;  
           }
             
         }
   }
    
     for(i = 1; i < n; i++)
     {
       if(n%2!=0)
       {
        output[n/2]=input[n];
        if(i/2!=0)
         {
          output(n/2-i) = input[n-i];
         }
        if(i/2 ==0)
        {
          output[n/2+i]=input[n-i];
        }
      }
     else
     {
      output[n/2+1]=intput[n];
      if(i/2!=0)
         {
          output(n/2+1-i) = input[n-i];
         }
        if(i/2 ==0)
        {
          output[n/2+1+i]=input[n-i];
        }
     }   

   } --------------------编程问答-------------------- void sort(int input[], int n, int output[])
{
   int temp;
   int i,j,k;
   for(i = 0; i < n-1; i++) 
   {
      for(j = i+1;j< n ;j++)
         {
          if(input[i]>input[j])
           {
             temp = input[i];
             input[i] =input[j];
             input[j]=temp;  
           }
             
         }
   }
    
     for(i = 1; i < n; i++)
     {
       if(n%2!=0)
       {
        output[n/2]=input[n];
        if(i/2!=0)
         {
          output(n/2-i) = input[n-i];
         }
        if(i/2 ==0)
        {
          output[n/2+i]=input[n-i];
        }
      }
     else
     {
      output[n/2+1]=intput[n];
      if(i/2!=0)
         {
          output(n/2+1-i) = input[n-i];
         }
        if(i/2 ==0)
        {
          output[n/2+1+i]=input[n-i];
        }
     }   

   } --------------------编程问答--------------------
#include<iostream>
#include<string.h>
using namespace std;
int cal_score(int score[],int judge_type[],int n)
{
int public_number=0;
int professor_sum=0;
int public_sum=0;
for(int i=0;i<n;i++)
{
if(judge_type[i]==1)
{
professor_sum+=score[i];
}
else if(judge_type[i]==2)
{
public_number+=1;
public_sum+=score[i];
}
}
if(public_number==0)
return professor_sum/n;
else
{
if(public_number<n)
{
return static_cast<int>(static_cast<int>(professor_sum/(n-public_number)*0.6)+static_cast<int>(public_sum/public_number*0.4));
}
//开始没有考虑到这个情况,思考要全面
else if(public_number==n)
{
return static_cast<int>(public_sum/public_number*0.4);
}
}
}
void sort_own(int input[],int n,int output[])
{
//时间复杂度,空间复杂度,都有待改善
int* t=new int[n];
memcpy(t,input,sizeof(int)*n);
//冒泡排序
for(int i=0;i<n-1;i++)
{
for(int j=0;j<n-i-1;j++)
{
if(t[j]>t[j+1])
{
//交换t[j],t[j]
t[j]^=t[j+1];
t[j+1]^=t[j];
t[j]^=t[j+1];
}
}
}
output[n/2]=t[n-1];
int left=n/2-1;
int right=n/2+1;
for(int i=n-2,j=1;i>=0;i--,j++)
{
if(j%2==1)
{
output[left]=t[i];
left--;
}
else
{
output[right]=t[i];
right++;
}
}
}
void scheduler(int task[],int n,int system_task[],int user_task[])
{
int** _task=new int*[n];
for(int i=0;i<n;i++)
{
_task[i]=new int[2];
_task[i][0]=i;
_task[i][1]=task[i];
}
//稳定的冒泡排序
for(int i=0;i<n-1;i++)
{
for(int j=0;j<n-i-1;j++)
{
if(_task[j][1]>_task[j+1][1])
{
int f=_task[j][0],s=_task[j][1];
_task[j][0]=_task[j+1][0];
_task[j][1]=_task[j+1][1];
_task[j+1][0]=f;
_task[j+1][1]=s;
}
}
}
int system_i=0,user_i=0;
for(int i=0;i<n;i++)
{
if(_task[i][1]<50)
{
system_task[system_i++]=_task[i][0];
}
//开始没有考虑>255的,现在考虑事情,总是漏掉一些
else if(_task[i][1]>=50&&_task[i][1]<=255)
{
user_task[user_i++]=_task[i][0];
}
}
system_task[system_i]=user_task[user_i]=-1;
}
void print(int a[])
{
int i=0;
while(a[i]!=-1)
{
cout<<a[i]<<endl;
i++;
}
}
int main()
{
//一个解法
/*第三题
int task[]={0,30,155,1,80,300,170,40,99};
int n=sizeof(task)/sizeof(*task);
int* system_task=new int[n];
int* user_task=new int[n];
scheduler(task,n,system_task,user_task);
print(system_task);
cout<<"---------"<<endl;
print(user_task);
*/
/*第二题
int input[]={};
int n=sizeof(input)/sizeof(*input);
int* output=new int[n];
sort_own(input,n,output);
for(int i=0;i<n;i++)
cout<<output[i]<<endl;
*/
/* 第一题
int score[]={12,10};
int judge_type[]={2,2};
int n = sizeof(score)/sizeof(*score);
cout<<cal_score(score,judge_type,n)<<endl;
*/

return 0;
}

--------------------编程问答-------------------- 华为最重视的就是基础! --------------------编程问答-------------------- 神马语言写?c or Java --------------------编程问答-------------------- 这题目偏简单了哦,已经没有区分度了,随便抓个人都能写。。。 --------------------编程问答-------------------- 路过,学习了 
--------------------编程问答-------------------- MARK!! --------------------编程问答-------------------- mark --------------------编程问答-------------------- mark --------------------编程问答-------------------- mark
明天做。
--------------------编程问答-------------------- 谢谢楼主 --------------------编程问答-------------------- 3.
public class TaskTest{

public static void main(String[] agrs){
int task[] = {0, 30, 155, 1, 80, 300, 170, 40, 99}; 
int[] system_task = new int[5];
int[] user_task = new int[5];
int n = task.length;
print(task);
System.out.println();
scheduler(task,n,system_task,user_task);
print(system_task);
System.out.println();
print(user_task);
}

static void scheduler(int task[], int n, int system_task[], int user_task[]){
int sysIdx = 0;
int userIdx = 0;
for(int i=0;i<n;i++){
if(task[i]<50){
system_task[sysIdx] = i;
sysIdx++;
if(sysIdx==system_task.length-1){
system_task[sysIdx] = -1;
}
}else if(task[i]<=255){
user_task[userIdx] = i;
userIdx++;
if(userIdx==user_task.length-1){
user_task[userIdx] = -1;
}
}else{
//do nothing
}
}
}

public static void print(int[] arrs){
int leng = arrs.length;
for(int i=0;i<arrs.length;i++){
if(i==0){
System.out.print("[");
}
if(i==leng-1){
System.out.print(arrs[i]+"]");
break;
}
System.out.print(arrs[i]+",");
}
}
} --------------------编程问答-------------------- 华为的,果断要顶起来。。。 --------------------编程问答-------------------- 对函数接口不懂啊?求解! --------------------编程问答-------------------- 第二个

public class HuaWei {

public static void main(String[] args) {
int input[] ={3, 6, 1, 9, 7, 8} ;
int output[] = new int[input.length];
sort(input, input.length, output);

}

public static void sort(int input[], int k, int output[]) {
//插入排序
for (int n = 0; n < input.length;n++) {
int max = 0;
int index = 0;
for (int i = n; i < input.length; i++) {
if (input[i] > max) {
max = input[i];
index = i;
}
}
int temp = input[n];
input[n] = max;
input[index] = temp;
}
//打印
for (int l : input) {
System.out.print(l);
}
System.out.print("\n");

for(int i=0;i<input.length;i++){
if(i%2==0){
output[output.length/2+i/2] = input[i];
}else{
output[output.length/2-i/2-1] = input[i];
}
}
for (int l : output) {
System.out.print(l);
}
}
}
补充:Java ,  Java SE
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,