当前位置:网站首页>Huawei machine test questions
Huawei machine test questions
2022-07-02 07:23:00 【Drizzle】
1
Now there are multiple sets of integer arrays , You need to merge them into a new array . Merger rules , Take out the fixed length contents from each array in order and merge them into a new array , The retrieved content will be deleted , If the line is less than a fixed length or is already empty , Then directly take out the contents of the remaining part and put it into the new array , Continue to the next line .
Input description :
The first line is a fixed length for each read , length >0
The first 2-n Rows are arrays that need to be merged , Different arrays are divided by carriage return and line feed , The inside of the array is separated by commas
Output description :
Output a new array , Separate with commas
Example :
Input :
3
2,5,6,7,9,5,7
1,7,4,3,4
Output :
2,5,6,1,7,4,7,9,5,3,4,7
Example :
Input :
4
2,5,6,7,9,5,7
1,7,4,3,4
Output :
2,5,6,7,1,7,4,3,9,5,7,4
Code implementation :
package com.ycr;
import java.util.ArrayList;
import java.util.Scanner;
public class Q1 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int fixedLength = Integer.valueOf(scanner.nextLine().trim());
ArrayList<ArrayList<String>> list = new ArrayList<>();
String [] tempInt;
ArrayList<String> tempString;
while(scanner.hasNext()) {
//for(int k = 0; k < 2; k ++) {
tempInt = scanner.nextLine().split(",");
tempString = new ArrayList<>();
for(int i = 0; i < tempInt.length; i ++) {
tempString.add(tempInt[i]);
}
list.add(tempString);
}
scanner.close();
StringBuilder out = new StringBuilder();
final String comma = ",";
while(!AllEmpty(list)) {
for(int i = 0; i< list.size(); i ++) {
if(list.get(i).isEmpty()) {
continue;
}
int j = 0;
while(j < fixedLength) {
if(list.get(i).isEmpty()) {
break;
}
out.append(list.get(i).get(0));
out.append(comma);
j ++;
list.get(i).remove(0);
}
}
}
System.out.print(out.substring(0, out.length() - 1));
}
static boolean AllEmpty(ArrayList<ArrayList<String>> list) {
for(int i = 0; i< list.size(); i ++) {
if(!list.get(i).isEmpty()) {
return false;
}
}
return true;
}
}
2
Check the input string for illegal characters , Output legal string ( duplicate removal ) And illegal string ( No weight removal )
Rotate the legal string left 10 Time , Then sort the output .( give an example : Like strings “abc”, The result of moving left once in a cycle is “bca”)
Input description :
(1) The character set in the string is ’0’ - ‘9’,‘a’ - ‘z’,‘A’ - ‘Z’, The rest are illegal characters ( Empty string as delimiter ), Strings with illegal characters are considered illegal input
(2) The number of input strings should not exceed 100, Each string is no longer than 64
(3) Continuous empty string as input ( Space / tabs / enter / A newline ) Treat as a space ( As a delimiter , The starting character of the string is not empty )
(4) Input only one string per line
(5) Input ends with a blank line
Output description :
(1) Output legal strings and remove duplicates
(2) Output all illegal strings
(3) For the result (1) The string of the de duplication method moves left circularly 10 Time
(4) For the result (3) Legal string sorting , Press ASCII The table characters are sorted from small to large
matters needing attention :
Each output string is separated from the next string with a space , There can only be one space between all strings as output ( As a delimiter )
Example :
Input :
abc
adf
==
acd123
44234tjg
aga'-=
ad--s
abd
123
abcdef
123456789012345678901234567890123456789012345678901234567890123
EDFG
SDFG
ABC
DEF
cccc
a*b=1
abc
cccc
dd
def
87&&^
wait …………
Output :
4 Outputs , No more fighting ...
Half the code :
Hang in the air : duplicate removal ( By using HashSet Automatic de duplication function )、 Sort ( By implementing Comparable Interface completion )
package com.ycr;
import java.util.ArrayList;
import java.util.Scanner;
public class Q2 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String temp;
final String end = "";
final String space = " ";
StringBuilder valid = new StringBuilder();
StringBuilder inValid = new StringBuilder();
StringBuilder afterLeft = new StringBuilder();
ArrayList<StringBuilder> validList = new ArrayList<>();
while(true) {
temp = scanner.nextLine();
if(temp.trim().equals(end)) {
break;
}
if(isValid(temp)) {
valid.append(temp);
validList.add(new StringBuilder(temp));
valid.append(space);
} else {
inValid.append(temp);
inValid.append(space);
}
}
scanner.close();
for(int i = 0; i < validList.size(); i ++) {
afterLeft.append(left(validList.get(i)));
afterLeft.append(space);
}
System.out.println(valid.substring(0, valid.length() - 1));
System.out.println(inValid.substring(0, inValid.length() - 1));
System.out.println(afterLeft.substring(0, afterLeft.length() - 1));
}
static StringBuilder left(StringBuilder s) {
int LEN = 10 % s.length();
return new StringBuilder(s.substring(LEN)).append(s.substring(0, LEN));
}
static boolean isValid(String s) {
for(int i = 0; i < s.length(); i ++) {
if(!isValid(s.charAt(i))) {
return false;
}
}
return true;
}
static boolean isValid(char c) {
return c >= '0' && c <= '9' || c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z';
}
}
3
Because I am not involved , Not excerpted ...
边栏推荐
- [introduction to information retrieval] Chapter 1 Boolean retrieval
- Transform the tree structure into array in PHP (flatten the tree structure and keep the sorting of upper and lower levels)
- 【信息检索导论】第一章 布尔检索
- The boss said: whoever wants to use double to define the amount of goods, just pack up and go
- SSM student achievement information management system
- [medical] participants to medical ontologies: Content Selection for Clinical Abstract Summarization
- One field in thinkphp5 corresponds to multiple fuzzy queries
- Pratique et réflexion sur l'entrepôt de données hors ligne et le développement Bi
- parser.parse_args 布尔值类型将False解析为True
- [introduction to information retrieval] Chapter 7 scoring calculation in search system
猜你喜欢

Interpretation of ernie1.0 and ernie2.0 papers
![[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

架构设计三原则

Implementation of purchase, sales and inventory system with ssm+mysql

Oracle EBS ADI development steps

【模型蒸馏】TinyBERT: Distilling BERT for Natural Language Understanding

离线数仓和bi开发的实践和思考

TCP攻击

離線數倉和bi開發的實踐和思考

Message queue fnd in Oracle EBS_ msg_ pub、fnd_ Application of message in pl/sql
随机推荐
SSM supermarket order management system
叮咚,Redis OM对象映射框架来了
pySpark构建临时表报错
Classloader and parental delegation mechanism
Cognitive science popularization of middle-aged people
Delete the contents under the specified folder in PHP
Oracle EBS interface development - quick generation of JSON format data
Take you to master the formatter of visual studio code
Oracle apex 21.2 installation and one click deployment
使用Matlab实现:Jacobi、Gauss-Seidel迭代
Explain in detail the process of realizing Chinese text classification by CNN
oracle EBS标准表的后缀解释说明
SSM personnel management system
数仓模型事实表模型设计
ORACLE EBS DATAGUARD 搭建
Spark SQL task performance optimization (basic)
Agile development of software development pattern (scrum)
[paper introduction] r-drop: regulated dropout for neural networks
MapReduce与YARN原理解析
CONDA creates, replicates, and shares virtual environments