当前位置:网站首页>Huawei machine test questions-20190417
Huawei machine test questions-20190417
2022-07-02 07:24:00 【Drizzle】
Introduce
This machine test question , Time of occurrence :2019 year 04 month 17 Japan ,19:00.
Last exam question , Time of occurrence :2019 year 04 month 03 Japan ,19:00.
This machine test 3 topic , all AC.
1
Title Description :
Given an array , There are 6 It's an integer , Find the maximum that this array can represent 24 What's the base time , Output this time , Cannot represent output invalid.
Input description :
The input is an array of integers , There are six integers in the array .
The length of the input integer array is 6, There is no need to consider other lengths , The element value is 0 Or a positive integer ,6 Each number can only be used once .
Output description :
Output as a 24 Time in hexadecimal format , Or string “invalid”.
Example 1
Input
[0,2,3,0,5,6]
Output
23:56:00
Example 2
Input
[9,9,9,9,9,9]
Output
invalid
remarks :
The output time format is xx:xx:xx Format .
Code
// Direct violence solution .
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
final String s = "invalid";
final String c = ":";
Scanner in = new Scanner(System.in);
String tempString = in.nextLine();
in.close();
tempString = tempString.substring(1, tempString.length() - 1);
String [] tempInt = tempString.split(",");
tempString = null;
int [] input = new int [6];
for(int i = 0; i < 6; i ++) {
input[i] = Integer.parseInt(tempInt[i]);
}
tempInt = null;
Arrays.sort(input);
ArrayList<Integer> list = new ArrayList<>();
for(int i = 0; i < 6; i ++) {
list.add(input[i]);
}
input = null;
StringBuilder output = new StringBuilder();
int i = getSpeci(list, 3); // first place
if(i != -1 ) {
output.append(list.remove(i));
} else {
System.out.print(s);
return ;
}
if(output.charAt(0) == '2') {
i = getSpeci(list, 4); // Second
if(i != -1 ) {
output.append(list.remove(i));
output.append(c);
}else {
System.out.print(s);
return ;
}
} else {
i = getSpeci(list, 10); // Second
if(i != -1 ) {
output.append(list.remove(i));
output.append(c);
}else {
System.out.print(s);
return ;
}
}
i = getSpeci(list, 6); // Third
if(i != -1 ) {
output.append(list.remove(i));
}else {
System.out.print(s);
return ;
}
i = getSpeci(list, 10); // Fourth place
if(i != -1 ) {
output.append(list.remove(i));
output.append(c);
}else {
System.out.print(s);
return ;
}
i = getSpeci(list, 6); // Fifth
if(i != -1 ) {
output.append(list.remove(i));
}else {
System.out.print(s);
return ;
}
i = getSpeci(list, 10); // Sixth place
if(i != -1 ) {
output.append(list.remove(i));
}else {
System.out.print(s);
return ;
}
System.out.print(output);
}
static int getSpeci(ArrayList<Integer> list, int speci) {
for(int i = list.size() - 1; i > -1; i --) {
if(list.get(i) < speci) {
return i;
}
}
return -1;
}
}
2
Title Description :
Xiao Wang has a little spare money , I want to do some small business selling fruits . Give two arrays m、n, use m[i] On behalf of the i The cost price of a fruit ,n[i] On behalf of the i The price at which fruit can be sold , If you have capital now k, How much money can you earn at most in the end ?
explain :
1 You only need to buy each kind of fruit once , It can only be sold once
2 Array m、n Not larger than 50
3 Array elements are positive integers , No more than 1000
Input description :
1 Array m、n
2 capital k
remarks :
1 Enter a comma separated array on the first line m The element value of
2 In the second line, enter a comma separated array n The element value of
3 On the third line, enter the capital
Output description :
How much money can you earn at most .
Example 1
Input
4,2,6,4
5,3,8,7
15
Output
22
explain
Example calculation process :
Before buying first 3 Kind of fruit , Sell all , Buy again 4 Kind of fruit , Resell , Finally, the principal becomes 22.
Code
import java.util.Arrays;
import java.util.Scanner;
public class Main {
static class B implements Comparable<B> {
int m;
int n;
B(int m, int n) {
this.m = m;
this.n = n;
}
@Override
public int compareTo(B o) {
if(m > o.m) {
return 1;
}
if(m < o.m) {
return -1;
}
if(n > o.n) {
return -1;
}
if(n < o.n) {
return 1;
}
return 0;
}
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String [] mm = in.nextLine().split(",");
String [] nn = in.nextLine().split(",");
int k = in.nextInt();
B [] b = new B [mm.length];
for(int i = 0; i < b.length; i ++) {
b[i] = new B(Integer.parseInt(mm[i]), Integer.parseInt(nn[i]));
}
mm = null;
nn = null;
Arrays.sort(b);
for(int i = 0; i < b.length; i ++) {
if(k >= b[i].m && b[i].n > b[i].m) {
k += (b[i].n - b[i].m);
}
}
System.out.print(k);
in.close();
}
}
3
Title Description
A multiprocessor multiprocessor batch processing system allows all jobs to be transferred into memory at one time , And can execute in parallel , Its parallel number is equal to the number of processors . The system adopts SJF The scheduling method of ( The shortest work is preferred , When the system is scheduling , Always give priority to the jobs with the shortest processing time ).
Now the number of processors is given m, Number of assignments n, The processing time of each job is t1, t2, … tn.
When n>m when , First, deal with those with short time m Jobs enter the processor for processing , Others enter and wait , When a job is processed , Take out the jobs with the shortest processing time from the waiting queue in turn and enter the processing .
Find out how much time it takes the system to process all jobs ?
notes : Do not consider the consumption of job switching .
Input description :
Input 2 That's ok , First act 2 It's an integer ( Space separated ), Respectively identify the number of processors m Number of jobs n; Second line input n It's an integer ( Space separated ), Identify the processing time of each job t1, t2,… tn.0<m, n<100,0<t1, t2,… tn<100.
Output description :
Total output processing time
Example 1
Input
3 5
8 4 3 1 10
Output
13
remarks :
notes : Do not consider the legitimacy of input .
Code :
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
public class Main{
static class CPU{
int time;
CPU() {
time = 0;
}
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int m = in.nextInt();
int n = in.nextInt();
int [] task = new int [n];
for(int i = 0; i < n; i ++) {
task[i] = in.nextInt();
}
in.close();
ArrayList<CPU> cpu = new ArrayList<>();
for(int i = 0; i < m; i ++) {
cpu.add(new CPU());
}
Arrays.sort(task);
int total = 0;
int index = 0;
while(true) {
int i = getZero(cpu);
if(i == 101) {
break;
}
if(i >= 0) {
if(index == n) {
cpu.remove(i);
} else {
cpu.get(i).time = task[index];
index ++;
}
} else {
total -= i;
}
}
System.out.print(total);
}
static int getZero(ArrayList<CPU> cpu) {
if(cpu.size() == 0) {
return 101;
}
int min = 100;
for(int i = 0; i < cpu.size(); i ++) {
if(cpu.get(i).time == 0) {
return i;
}
min = min > cpu.get(i).time ? cpu.get(i).time : min;
}
for(int i = 0; i < cpu.size(); i ++) {
cpu.get(i).time -= min;
}
return -min;
}
}
边栏推荐
- 一份Slide两张表格带你快速了解目标检测
- Oracle EBS DataGuard setup
- Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory'
- oracle apex ajax process + dy 校验
- 【信息检索导论】第六章 词项权重及向量空间模型
- Oracle general ledger balance table GL for foreign currency bookkeeping_ Balance change (Part 1)
- 优化方法:常用数学符号的含义
- Check log4j problems using stain analysis
- 如何高效开发一款微信小程序
- 华为机试题-20190417
猜你喜欢
Proteus -- RS-232 dual computer communication
[introduction to information retrieval] Chapter 1 Boolean retrieval
JSP智能小区物业管理系统
Two table Association of pyspark in idea2020 (field names are the same)
The boss said: whoever wants to use double to define the amount of goods, just pack up and go
Message queue fnd in Oracle EBS_ msg_ pub、fnd_ Application of message in pl/sql
【信息检索导论】第三章 容错式检索
How to efficiently develop a wechat applet
TCP攻击
【MEDICAL】Attend to Medical Ontologies: Content Selection for Clinical Abstractive Summarization
随机推荐
优化方法:常用数学符号的含义
一个中年程序员学习中国近代史的小结
ORACLE EBS中消息队列fnd_msg_pub、fnd_message在PL/SQL中的应用
Transform the tree structure into array in PHP (flatten the tree structure and keep the sorting of upper and lower levels)
Analysis of MapReduce and yarn principles
Use matlab to realize: chord cut method, dichotomy, CG method, find zero point and solve equation
Error in running test pyspark in idea2020
Sqli labs customs clearance summary-page1
allennlp 中的TypeError: Object of type Tensor is not JSON serializable错误
Cloud picture says | distributed transaction management DTM: the little helper behind "buy buy buy"
oracle EBS标准表的后缀解释说明
腾讯机试题
Oracle rman半自动恢复脚本-restore阶段
Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory'
Check log4j problems using stain analysis
[model distillation] tinybert: distilling Bert for natural language understanding
实现接口 Interface Iterable&lt;T&gt;
CRP implementation methodology
使用MAME32K进行联机游戏
Oracle apex Ajax process + dy verification