-
Notifications
You must be signed in to change notification settings - Fork 7
/
Main.java
50 lines (44 loc) · 1.17 KB
/
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package basicLevel1033;
// 测试点4错误
// 可以使用C++
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String badKeyInput = in.nextLine();
String testKey = in.nextLine();
in.close();
// 判断上档键是否在坏掉的键盘里面
boolean noShiftKey = true;
Set<Character> set = new HashSet<>(); // 将坏掉的键放入散列表里面,方便查找
for (int i = 0; i < badKeyInput.length(); i++) {
char c = badKeyInput.charAt(i);
if (c == '+') {
noShiftKey = false;
}
set.add(c);
set.add(Character.toLowerCase(c));
}
if (noShiftKey) {
// 上档键不在坏掉的键里面,可以输出大写的
for (int i = 0; i < testKey.length(); i++) {
char c = testKey.charAt(i);
if (!set.contains(c)) {
System.out.print(c);
}
}
} else {
// 上档键在坏掉的键,如果是大写的,则不输出
for (int i = 0; i < testKey.length(); i++) {
char c = testKey.charAt(i);
if (!Character.isUpperCase(c)) {
if (!set.contains(c)) {
System.out.print(c);
}
}
}
}
}
}