华为OD机考题(基础API)

基础API

字典排序

复制代码
List<String> list=new ArrayList();
//add list member
Arrays.sort(list);

List<Map<String,Integer>> list=new ArrayList();
//add list member
Collections.sort(list, new Comparator<Map.Entry<String, Integer>>() {
   @Override
   public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2{
        return o2.getValue()-o1.getValue();
   }
});

进制转换

Integer.parseInt(hexString, 16)//16进制转10进制

Integer.toBinaryString(num);//十进制转二进制

int decimal = Integer.parseInt(binaryString, 2);//二进制转10进制

>> 有符号右移

>>>无符号右移

bit处理​​​​​​

​Integer.bitCount(n);//二进制中1的个数

字典排序示例:

复制代码
package huaweiod;

import java.util.*;

public class Test{
    public static void main(String[] args) throws Exception{
        Map<String,Map<String,Integer>> map=new HashMap();
        Map<String,Integer> map1=new HashMap();
        map1.put("004",160);
        map1.put("003",150);
        map1.put("002",150);
        map1.put("001",160);
        map1.put("005",150);
        map.put("02",map1);

        Map<String,Integer> map2=new HashMap();
        map2.put("003",130);
        map2.put("004",140);
        map.put("01",map2);

        Set<String> classNum=map.keySet();
        Object[] array=classNum.toArray();
        Arrays.sort(classNum.toArray());
        for(Object o:array){
            System.out.println("class:"+o);
            HashMap<String,Integer> tempMap=(HashMap)map.get(o);
            List<Map.Entry<String,Integer>> list=new ArrayList(tempMap.entrySet());
            Collections.sort(list, new Comparator<Map.Entry<String, Integer>>() {
                @Override
                public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
                    return o2.getValue()-o1.getValue();
                }
            });
            for(Map.Entry<String,Integer> entry:list){
                System.out.println(entry.getKey()+":"+entry.getValue());
            }
        }
    }
}
相关推荐
无限码力16 小时前
华为OD技术面真题 - Python开发 - 4
python·华为od·华为od技术面真题·华为od面试八股文·华为od面试真题·华为odpython开发真题·华为od技术面题目
无限码力3 天前
华为OD机试真题 新系统 - 直捣黄龙 (C/C++/Py/Java/Js/Go)
华为od·华为od机试真题·华为od上机考试真题·华为od机考真题·华为od新系统机试真题·华为od4月8号机试真题
无限码力5 天前
华为OD技术面真题 - JAVA开发- spring框架 - 7
java·开发语言·华为od·华为od面试真题·华为odjava八股文·华为odjava开发题目·华为odjava开发高频题目
无限码力19 天前
华为OD机试双机位C卷真题-红黑图(C/C++/Py/Java/Js/Go)
华为od·华为od机试真题·华为od机试双机位c卷·华为od上机考试真题·华为od机考真题·华为od机试-红黑图·华为od机考真题-红黑图
无限码力19 天前
华为OD机试双机位C卷-用户入网定期复评(C/C++/Py/Java/Js/Go)
华为od·华为od机试真题·华为od机试双机位c卷·华为od上机考试真题·华为od机考真题·华为od-用户入网定期复评
gis分享者20 天前
华为OD面试-Java、C++、Pyhton等多语言实现-目录
java·c++·华为od·面试·目录·od·机试
无限码力21 天前
华为OD机试双机位C卷-虚拟文件系统(C/C++/Py/Java/Js/Go)
华为od·华为od机试真题·华为od机试双机位c卷·华为od上机考试真题·华为od机考真题·华为od-虚拟文件系统·华为od机试题库
sprite_雪碧23 天前
考研机试笔记-1输入输出
笔记·考研·华为od
无限码力1 个月前
华为OD机试真题2026双机位C卷 C++实现【日志解析】
c++·华为od·华为od机试真题·华为od机考真题·华为od机试真题-日志解析
uesowys1 个月前
华为OD算法开发指导-数据结构-图
数据结构·算法·华为od