【197期】华为OD两轮技术面试记录,给后来人一个参考!
共 4984字,需浏览 10分钟
·
2021-05-20 03:28
阅读本文大概需要 2 分钟。
来自:blog.csdn.net/candgbb/article/details/103877203
1性格测试
2机试
20M
1T
300G
20M
300G
1T
package Huawei;
import java.util.Scanner;
/**
* Created by xuzhenyu on 2020/1/5.
*/
public class Test {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
String[] strings = new String[n];
for (int i = 0; i < n; i++) {
strings[i] = scanner.next();
}
String[] ruslutStrs = sort(strings);
for (int i = 0; i <ruslutStrs.length ; i++) {
System.out.println(ruslutStrs[i]);
}
}
private static String[] sort(String[] strs) {
for (int i = 0; i < strs.length - 1; i++) {
for (int j = 0; j < strs.length - i - 1; j++) {
// M G T
if (compare(strs[j], strs[j + 1])) {
String tem = strs[j];
strs[j] = strs[j+1];
strs[j+1] = tem;
}
}
}
return strs;
}
private static boolean compare(String str1, String str2){
int str1M = turnString(str1);
int str2M = turnString(str2);
return str1M>str2M;
}
private static int turnString(String str){
if("M".equals(String.valueOf(str.charAt(str.length()-1)))){
return Integer.parseInt(str.substring(0,str.length()-1));
}
else if ("G".equals(String.valueOf(str.charAt(str.length()-1)))){
return Integer.parseInt(str.substring(0,str.length()-1))*1000;
}
else if ("T".equals(String.valueOf(str.charAt(str.length()-1)))){
return Integer.parseInt(str.substring(0,str.length()-1))*1000000;
}
return 0;
};
}
3面试
3.1.两道编程题
3.2.面试问题
推荐阅读:
【195期】MySQL中的条件判断函数 CASE WHEN、IF、IFNULL你会用吗?
【194期】Redis——第三方jar没有封装的命令我们该怎么执行?
微信扫描二维码,关注我的公众号
朕已阅