当前位置:网站首页>Huawei computer test ~ offset realizes string encryption
Huawei computer test ~ offset realizes string encryption
2022-07-26 13:24:00 【weixin_ forty-three million seven hundred and sixty-six thousan】
1. Title Description : Give the original string str, Encryption is achieved by changing each letter of the string , The encryption method is in every letter str[i] Offset a specific array element a[i] The amount of . Array a The first three digits of have been assigned :a[0]=1,a[1]=2,a[2]=4, When i>=3 when , Array elements a[i]=a[i-1]+a[i-2]+a[i-3].
- for example : original text abcde After encryption bdgkr, The offsets are 1,2,4,7,13.
- Input description : The first line is an integer n, Express n Group test data . Each set of data contains a row , original text str( Contains only lowercase letters , Longer than 0 Less than 50).
- Output description : Each group of test data output one line , It means ciphertext .
// String offset xy -> ya , abcde -> bdgkr
public static void tm001(){
Scanner scanner = new Scanner(System.in);
while (scanner.hasNext()){
String line1 = scanner.nextLine();
int count = Integer.parseInt(line1);
List<String> stringList = new ArrayList<>();
int maxLen = 0;
for (int i = 0; i < count; i++) {
String input = scanner.nextLine();
if (input.length() > maxLen){
maxLen = input.length();
}
stringList.add(input);
}
// Calculate directly from the maximum length Move step set Calculate only once
int[] moveArr = new int[Math.max(maxLen, 3)];
moveArr[0] = 1;
moveArr[1] = 2;
moveArr[2] = 4;
for (int i = 3; i < maxLen; i++) {
// When adding Take the remainder Prevent the stack from exceeding int Range
// in consideration of Integer.MAX_VALUE = 2147483647, Directly remainder the result Ensure that each number is not greater than 26
moveArr[i] = (moveArr[i-1] + moveArr[i-2] + moveArr[i-3]) % 26;// 26 Letters
}
for (String line : stringList) {
char[] chars = line.toCharArray();
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < chars.length; i++) {
int move = moveArr[i];
// 'a' = 97 , 'z' = 122
// prevent appear 25 + 25 Etc. greater than 26 The situation of Take the mold again
int result = ((chars[i] - 97) + move)%26 + 97; // 26 Letters Subscript from 0 Start ~25
stringBuilder.append((char)result);
}
System.out.println(stringBuilder);
}
}
}
边栏推荐
- Mysql数据目录(1)---数据库结构(二十四)
- B+树(3)聚簇索引,二级索引 --mysql从入门到精通(十五)
- Golang port scanning design
- B+ tree index use (6) leftmost principle -- MySQL from entry to proficiency (18)
- 牛客刷SQL---2
- 详解关系抽取模型 CasRel
- [applet] why can't the onreachbottom event be triggered? (one second)
- Solution 5g technology helps build smart Parks
- B+树(4)联合索引 --mysql从入门到精通(十六)
- Dimension disaster dimension disaster suspense
猜你喜欢

多线程使用不当导致的 OOM

基于C#实现的学生考试系统

Emotion analysis model based on Bert

El table implements editable table

从其他文件触发pytest.main()注意事项

Kubernetes apiserver current limiting strategy

HCIP第十一天比较(BGP的配置、发布)

Hcip day 12 notes sorting (BGP Federation, routing rules)

Basic sentence structure of English ----- origin

Kubelet CRI container runtime
随机推荐
概率论与数理统计
How to realize the reality of temporary graphic elements
银行业客户体验管理现状与优化策略分析
Dimension disaster dimension disaster suspense
7-25 0-1 backpack (50 points)
Streamnational team culture: a "transparent" company
JSON格式执行计划(6)—mysql执行计划(五十二)
Detailed explanation of factory mode
HCIP第十二天笔记整理(BGP联邦、选路规则)
Elementary notes of binary tree
B+ tree (3) clustered index, secondary index -- MySQL from entry to proficiency (XV)
MVVM architecture encapsulation of kotlin series (kotlin+mvvm)
从其他文件触发pytest.main()注意事项
B+树索引使用(8)排序使用及其注意事项(二十)
Abstract factory and its improvement examples
JUC总结
B+ tree selection index (1) -- MySQL from entry to proficiency (22)
The child component triggers the defineemits of the parent component: the child component passes values to the parent component
Kubernetes apiserver current limiting strategy
pomerium