当前位置:网站首页>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 7 scoring calculation in search system
- CAD secondary development object
- [torch] some ideas to solve the problem that the tensor parameters have gradients and the weight is not updated
- ssm+mysql实现进销存系统
- 2021-07-05c /cad secondary development create arc (4)
- SSM student achievement information management system
- Oracle rman自动恢复脚本(生产数据向测试迁移)
- 类加载器及双亲委派机制
- Analysis of MapReduce and yarn principles
- 离线数仓和bi开发的实践和思考
猜你喜欢
随机推荐
【论文介绍】R-Drop: Regularized Dropout for Neural Networks
SSM二手交易网站
Oracle apex 21.2 installation and one click deployment
解决万恶的open failed: ENOENT (No such file or directory)/(Operation not permitted)
【Torch】最简洁logging使用指南
SSM laboratory equipment management
Sqli-labs customs clearance (less2-less5)
Sqli-labs customs clearance (less1)
Oracle 11g uses ords+pljson to implement JSON_ Table effect
Sqli labs customs clearance summary-page2
MySQL组合索引加不加ID
离线数仓和bi开发的实践和思考
【MEDICAL】Attend to Medical Ontologies: Content Selection for Clinical Abstractive Summarization
DNS攻击详解
MySQL composite index with or without ID
使用Matlab实现:弦截法、二分法、CG法,求零点、解方程
ssm人事管理系统
CONDA creates, replicates, and shares virtual environments
Sqli labs customs clearance summary-page1
PHP uses the method of collecting to insert a value into the specified position in the array