当前位置:网站首页>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 ...
边栏推荐
- Explanation of suffix of Oracle EBS standard table
- oracle apex ajax process + dy 校验
- A summary of a middle-aged programmer's study of modern Chinese history
- 【MEDICAL】Attend to Medical Ontologies: Content Selection for Clinical Abstractive Summarization
- Only the background of famous universities and factories can programmers have a way out? Netizen: two, big factory background is OK
- [Bert, gpt+kg research] collection of papers on the integration of Pretrain model with knowledge
- Check log4j problems using stain analysis
- 【Torch】解决tensor参数有梯度,weight不更新的若干思路
- Interpretation of ernie1.0 and ernie2.0 papers
- Oracle rman自动恢复脚本(生产数据向测试迁移)
猜你喜欢

【信息检索导论】第六章 词项权重及向量空间模型

【信息检索导论】第二章 词项词典与倒排记录表

Pratique et réflexion sur l'entrepôt de données hors ligne et le développement Bi

ssm人事管理系统

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

【MEDICAL】Attend to Medical Ontologies: Content Selection for Clinical Abstractive Summarization

MySQL has no collation factor of order by

Sqli labs customs clearance summary-page2
![[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

JSP智能小区物业管理系统
随机推荐
Take you to master the formatter of visual studio code
Classloader and parental delegation mechanism
離線數倉和bi開發的實踐和思考
ORACLE EBS 和 APEX 集成登录及原理分析
Oracle 11.2.0.3 handles the problem of continuous growth of sysaux table space without downtime
Oracle EBS DataGuard setup
架构设计三原则
Alpha Beta Pruning in Adversarial Search
2021-07-05c /cad secondary development create arc (4)
TCP攻击
[torch] the most concise logging User Guide
The first quickapp demo
Oracle rman自动恢复脚本(生产数据向测试迁移)
【信息检索导论】第七章搜索系统中的评分计算
MySQL composite index with or without ID
JSP intelligent community property management system
离线数仓和bi开发的实践和思考
数仓模型事实表模型设计
ORACLE 11.2.0.3 不停机处理SYSAUX表空间一直增长问题
ssm人事管理系统