华为机试准备--练习(JAVA实现)

题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) 

 

public class HuaWeiTest4{
     public static void main(String[] args){
          int[] score = {80, 70, 85, 88, 90};
          int[] judge_type = {1,1,2,2,2};
          HuaWeiTest4 test = new HuaWeiTest4();
          int last_score = test.cal_score(score, judge_type,5);
          System.out.println("最终得分是:"+last_score);
     }
     public int cal_score(int score[], int judge_type[], int n){
          int totalExpert = 0;
          int totalPublic = 0;
          int numExpert = 0;
          int numPublic = 0;
          int result = 0;
          for(int i=0; i<n; i++){
              if(judge_type[i] == 1){
                 totalExpert += score[i];
                 numExpert++;
              }
              if(judge_type[i] == 2){
                 totalPublic += score[i];
                 numPublic++;
              }
          }
          if(0 == numPublic)
             result = totalExpert  / numExpert;
          else
             result = (int)((totalExpert * 1.0 / numExpert)*0.6 + (totalPublic*1.0/numPublic)*0.4);
          return result;
     }
}

编写一个算法,过滤掉数组中的非法字符,最终只剩下正式字符。

      示例:输入数组:“!¥@&HuaWei*&%123”

              调用函数后的输出结果,数组:“HuaWei123”。

函数声明:

public static void getFormatString(String s)

public class Test2{
    public static void main(String[] args){
       Test2 test = new Test2();
       String str ="!¥@&HuaWei*&%123";
       String res = test.formatString(str);
       System.out.println("过滤后的字符串是:" + res);
    }
    public String formatString(String str){
       int StrLength = str.length();
       String result ="";
       for(int i=0; i<StrLength; i++){
           if((str.charAt(i)>='A'&&str.charAt(i)<='Z') ||
               (str.charAt(i)>= 'a'&&str.charAt(i)<='z') ||
               (str.charAt(i)>='0'&&str.charAt(i)<='9'))
              result += str.charAt(i);
       }
       return result;
    }
}


 

判断一个数是否回文数,如果1221,232, 3;
【输入】:一个整型数iNumber
【输出】:0: iNumber不是回文数
          1:iNumber是回文数

import java.util.Scanner;

public class Test1{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入要判断的字符串:");
        String str = sc.nextLine();
        Test1 test = new Test1();
        test.isHuiWen(str);
    }
    public void isHuiWen(String str){
        int StrLength = str.length();
        int count = 0;
        boolean isYes = true;
        while(isYes){
            if(str.charAt(count+0) != str.charAt(StrLength -count-1))
              isYes = false;
            count++;
            if(count >= StrLength/2){
               System.out.println(str+"是回文字符串");
               isYes = false;
            }   
        }
        if(count < StrLength / 2)
          System.out.println(str+"不是回文字符串");
    } 
}


 

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
华为OD-2023真题主要考察了以下几个方面的知识点: 1. 数据结构与算法:题目涉及了常见的数据结构和算法,如数组、链表、树、图、排序、搜索等。要求考生熟悉这些数据结构的基本操作和常用算法的实现方法。 2. 编程语言:题目要求使用C++或Java语言完成编程任务,要求考生熟悉相应语言的语法和常用的库函数使用方法。 3. 网络通信:题目涉及了网络通信相关的知识点,如TCP/IP协议、HTTP协议、socket编程等。要求考生了解网络通信的基本概念和实现方式。 4. 操作系统:题目要求考生熟悉操作系统相关的知识,如进程管理、内存管理、文件系统等。要求考生了解操作系统的基本功能和实现原理。 5. 数据库:题目涉及了数据库相关的知识点,如SQL语句的编写、数据库的设计和优化等。要求考生具备数据库的基本操作和设计能力。 6. 设计模式:题目要求考生能够根据给定的需求设计相应的对象和类,并且符合设计模式的原则。要求考生熟悉常见的设计模式和其应用场景。 7. 系统设计与架构:题目要求考生从整体上设计和实现一个系统,并考虑系统的性能、可扩展性等因素。要求考生了解系统设计的基本原则和方法。 以上是华为OD-2023真题的一些考点分类。考生在复习备考时,可以根据这些考点有针对性地进行学习和练习,提升自己的应能力。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值