旧键盘上坏了几个键,于是在敲一段文字的时候,对应的字符就不会出现。现在给出应该输入的一段文字、以及实际被输入的文字,请你列出肯定坏掉的那些键。
输入格式:
输入在 2 行中分别给出应该输入的文字、以及实际被输入的文字。每段文字是不超过 80 个字符的串,由字母 A-Z(包括大、小写)、数字 0-9、以及下划线 _
(代表空格)组成。题目保证 2 个字符串均非空。
输出格式:
按照发现顺序,在一行中输出坏掉的键。其中英文字母只输出大写,每个坏键只输出一次。题目保证至少有 1 个坏键。
输入样例:
7_This_is_a_test
_hs_s_a_es
输出样例:
7TI
#include<stdio.h>
#include<string.h>
int main()
{
char ch_dream[100] = {},ch_real[100] = {};
gets(ch_dream);
gets(ch_real);
int index1 = 0,index2 =0,index_save = 0;
char ch_save[100] = {}; //保存坏掉的键
while('\0' != ch_dream[index1])
{
if(ch_dream[index1] != ch_real[index2])
{
ch_save[index_save++] = ch_dream[index1];
index1++;
}
else
{
index1++;
index2++;
}
}
int l = strlen(ch_save);
char ch_resu[100] = {};
for(int i = 0 ; i < l ; i++) //筛选重复的键
{
for(int j = i+1 ; j < l ; j++)
{
if('\0' == ch_save[i])
break;
if(ch_save[j] == ch_save[i])
ch_save[j] = '\0';
else if(97 <= ch_save[j] && 122 >= ch_save[j] && ch_save[j] == ch_save[i] + 32)
ch_save[j] = '\0';
else if(65 <= ch_save[j] && 90 >= ch_save[j] && ch_save[j] == ch_save[i] - 32)
ch_save[j] = '\0';
}
if('\0' != ch_save[i] && 97 <= ch_save[i] && 122 >= ch_save[i])
printf("%c",ch_save[i] - 32);
else if('\0' != ch_save[i])
printf("%c",ch_save[i]);
}
return 0;
}