旧键盘上坏了几个键,于是在敲一段文字的时候,对应的字符就不会出现。现在给出应该输入的一段文字、以及坏掉的那些键,打出的结果文字会是怎样?
输入格式:
输入在 2 行中分别给出坏掉的那些键、以及应该输入的文字。其中对应英文字母的坏键以大写给出;每段文字是不超过 105 个字符的串。可用的字符包括字母 [a
-z
, A
-Z
]、数字 0
-9
、以及下划线 _
(代表空格)、,
、.
、-
、+
(代表上档键)。题目保证第 2 行输入的文字串非空。
注意:如果上档键坏掉了,那么大写的英文字母无法被打出。
输出格式:
在一行中输出能够被打出的结果文字。如果没有一个字符能被打出,则输出空行。
输入样例:
7+IE.
7_This_is_a_test.
输出样例:
_hs_s_a_tst
代码:
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
bool worn[45]={false};//表示题目中所述字符是否损坏
char input[100010],ch[45];//input存放应该输入的字符串,ch存放损坏的字符
char result[100010];//存放应该输出的字符
cin.getline(ch,45);//以防出现第一行即键盘没有损坏键的情况
cin.getline(input,100010);
int len1=strlen(input),len2=strlen(ch),len3=0;
for(int i=0;i<len2;i++)//标记损坏的键
{
if(ch[i]>='A'&&ch[i]<='Z')
worn[ch[i]-'A']=true;
else if(ch[i]>='0'&&ch[i]<='9')
worn[ch[i]-'0'+26]=true;
else if(ch[i]=='_')
worn[36]=true;
else if(ch[i]==',')
worn[37]=true;
else if(ch[i]=='.')
worn[38]=true;
else if(ch[i]=='-')
worn[39]=true;
else if(ch[i]=='+')
worn[40]=true;
}
for(int i=0;i<len1;i++)
{
if(input[i]>='a'&&input[i]<='z'&&worn[input[i]-'a']==false)
result[len3++]=input[i];
else if(input[i]>='A'&&input[i]<='Z'&&worn[input[i]-'A']==false&&worn[40]==false)
result[len3++]=input[i];
else if(input[i]>='0'&&input[i]<='9'&&worn[input[i]-'0'+26]==false)
result[len3++]=input[i];
else if(input[i]=='_'&&worn[36]==false)
result[len3++]='_';
else if(input[i]==','&&worn[37]==false)
result[len3++]=',';
else if(input[i]=='.'&&worn[38]==false)
result[len3++]='.';
else if(input[i]=='-'&&worn[39]==false)
result[len3++]='-';
}
if(len3==0)
printf("\n");
else
{
for(int i=0;i<len3;i++)
printf("%c",result[i]);
}
return 0;
}