链接:旧键盘 (20)__牛客网
来源:牛客网
旧键盘上坏了几个键,于是在敲一段文字的时候,对应的字符就不会出现。现在给出应该输入的一段文字、以及实际被输入的文字,请你列出
肯定坏掉的那些键。
输入描述:
输入在2行中分别给出应该输入的文字、以及实际被输入的文字。每段文字是不超过80个字符的串,由字母A-Z(包括大、小写)、数字0-9、 以及下划线“_”(代表空格)组成。题目保证2个字符串均非空。
输出描述:
按照发现顺序,在一行中输出坏掉的键。其中英文字母只输出大写,每个坏键只输出一次。题目保证至少有1个坏键。
示例1
输入
7_This_is_a_test _hs_s_a_es
输出
7TI
题解:
import java.util.*;
public class Main {
public static void func(String strExcep, String strActual) {
Set<Character> set1 = new HashSet<>();
Set<Character> set2 = new HashSet<>();
for (int i = 0; i < strActual.length(); i++) {
set1.add(Character.toUpperCase(strActual.charAt(i)));
}
for (int i = 0; i < strExcep.length(); i++) {
char ch = strExcep.charAt(i);
ch = Character.toUpperCase(ch);
if (set1.contains(ch) || set2.contains(ch)) continue;
else {
System.out.print(ch);
set2.add(ch);
}
}
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (scanner.hasNextLine()) {
String strExcep = scanner.nextLine();
String strActuall = scanner.nextLine();
func(strExcep, strActuall);
}
}
}









