当前位置:网站首页>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;
}
}
边栏推荐
- 【模型蒸馏】TinyBERT: Distilling BERT for Natural Language Understanding
- Classloader and parental delegation mechanism
- Yaml file of ingress controller 0.47.0
- [model distillation] tinybert: distilling Bert for natural language understanding
- TCP attack
- Spark SQL task performance optimization (basic)
- CRP实施方法论
- Oracle EBS interface development - quick generation of JSON format data
- MySQL has no collation factor of order by
- view的绘制机制(三)
猜你喜欢

SSM garbage classification management system

【Ranking】Pre-trained Language Model based Ranking in Baidu Search

Sparksql data skew

Analysis of MapReduce and yarn principles
![[introduction to information retrieval] Chapter 6 term weight and vector space model](/img/42/bc54da40a878198118648291e2e762.png)
[introduction to information retrieval] Chapter 6 term weight and vector space model

Network security -- intrusion detection of emergency response
![[introduction to information retrieval] Chapter 7 scoring calculation in search system](/img/cc/a5437cd36956e4c239889114b783c4.png)
[introduction to information retrieval] Chapter 7 scoring calculation in search system

ssm垃圾分类管理系统

oracle apex ajax process + dy 校验

Sqli labs customs clearance summary-page1
随机推荐
[tricks] whiteningbert: an easy unsupervised sentence embedding approach
Alpha Beta Pruning in Adversarial Search
Proteus -- RS-232 dual computer communication
[medical] participants to medical ontologies: Content Selection for Clinical Abstract Summarization
oracle apex ajax process + dy 校验
MySQL has no collation factor of order by
Agile development of software development pattern (scrum)
SSM supermarket order management system
Spark的原理解析
Pyspark build temporary report error
DNS攻击详解
2021-07-17c /cad secondary development creation circle (5)
oracle EBS标准表的后缀解释说明
优化方法:常用数学符号的含义
腾讯机试题
Message queue fnd in Oracle EBS_ msg_ pub、fnd_ Application of message in pl/sql
Only the background of famous universities and factories can programmers have a way out? Netizen: two, big factory background is OK
[model distillation] tinybert: distilling Bert for natural language understanding
JSP智能小区物业管理系统
【信息检索导论】第六章 词项权重及向量空间模型