当前位置:网站首页>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 ...
边栏推荐
- Module not found: Error: Can't resolve './$$_ gendir/app/app. module. ngfactory'
- 【信息检索导论】第一章 布尔检索
- 读《敏捷整洁之道:回归本源》后感
- Explanation of suffix of Oracle EBS standard table
- 【模型蒸馏】TinyBERT: Distilling BERT for Natural Language Understanding
- 【Torch】最简洁logging使用指南
- Pyspark build temporary report error
- [introduction to information retrieval] Chapter 6 term weight and vector space model
- RMAN增量恢复示例(1)-不带未备份的归档日志
- Oracle EBS DataGuard setup
猜你喜欢

【信息检索导论】第一章 布尔检索

第一个快应用(quickapp)demo

CAD secondary development object

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

spark sql任务性能优化(基础)

Classloader and parental delegation mechanism

Spark SQL task performance optimization (basic)

【信息检索导论】第三章 容错式检索

类加载器及双亲委派机制
![[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
随机推荐
Two table Association of pyspark in idea2020 (field names are the same)
Oracle EBS interface development - quick generation of JSON format data
Spark的原理解析
TCP attack
Oracle segment advisor, how to deal with row link row migration, reduce high water level
【BERT,GPT+KG调研】Pretrain model融合knowledge的论文集锦
ORACLE APEX 21.2安裝及一鍵部署
Oracle EBS ADI development steps
Pratique et réflexion sur l'entrepôt de données hors ligne et le développement Bi
Check log4j problems using stain analysis
使用Matlab实现:弦截法、二分法、CG法,求零点、解方程
SSM laboratory equipment management
解决万恶的open failed: ENOENT (No such file or directory)/(Operation not permitted)
【Ranking】Pre-trained Language Model based Ranking in Baidu Search
Delete the contents under the specified folder in PHP
Oracle 11g sysaux table space full processing and the difference between move and shrink
矩阵的Jordan分解实例
oracle-外币记账时总账余额表gl_balance变化(上)
ORACLE 11G利用 ORDS+pljson来实现json_table 效果
Oracle APEX 21.2 installation et déploiement en une seule touche