旧键盘上坏了几个键,于是在敲一段文字的时候,对应的字符就不会出现。现在给出应该输入的一段文字、以及实际被输入的文字,请你列出肯定坏掉的那些键。
输入格式:
输入在 2 行中分别给出应该输入的文字、以及实际被输入的文字。每段文字是不超过 80 个字符的串,由字母 A-Z(包括大、小写)、数字 0-9、以及下划线 _
(代表空格)组成。题目保证 2 个字符串均非空。
输出格式:
按照发现顺序,在一行中输出坏掉的键。其中英文字母只输出大写,每个坏键只输出一次。题目保证至少有 1 个坏键。
输入样例:
7_This_is_a_test
_hs_s_a_es
输出样例:
7TI
代码长度限制
16 KB
时间限制
200 ms
内存限制
64 MB
解题代码:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
String A = sc.next(), B = sc.next(), print = "";
int index = 0;
for (int i = 0; i < A.length(); i++) {
char c1 = A.charAt(i);
char c2 = 0;
if (index < B.length()) {
c2 = B.charAt(index);
}
if (c1 != c2) {
print += String.valueOf(c1).toUpperCase();
} else {
index++;
}
}
int[] arr = new int[128];
for (int i = 0; i < print.length(); i++) {
char c = print.charAt(i);
arr[c]++;
}
for (int i = 0; i < print.length(); i++) {
char c = print.charAt(i);
if (arr[c] > 0) {
arr[c] = 0;
System.out.print(c);
}
}
sc.close();
}
}