/*
题目描述
旧键盘上坏了几个键,于是在敲一段文字的时候,对应的字符就不会出现。现在给出应该输入的一段文字、以及坏掉的那些键,打出的结果文字会是怎样?
输入描述:
输入在2行中分别给出坏掉的那些键、以及应该输入的文字。其中对应英文字母的坏键以大写给出;每段文字是不超过10^5个字符的串。可用的字符包括字母[a-z, A-Z]、数字0-9、以及下划线“_”(代表空格)、“,”、“.”、“-”、“+”(代表上档键)。题目保证第2行输入的文字串非空。
注意:如果上档键坏掉了,那么大写的英文字母无法被打出。
输出描述:
在一行中输出能够被打出的结果文字。如果没有一个字符能被打出,则输出空行。
输入例子:
7+IE.
7_This_is_a_test.
输出例子:
_hs_s_a_tst
*/
#include<iostream>
#include<string>
using namespace std;
int main()
{
string str_wrong, str_right;
cin >> str_wrong >> str_right;
string temp1 = {}, temp2 = {};
// 若有 "+" 则删掉大写字符,并存放在 temp1 内,若没有则直接放入 temp1 内
// temp2 用来存放最后结果
int i, j;
for (i = 0; i < str_wrong.length(); i++) //判断是否有 "+",若有删掉大写字符
{
if (str_wrong[i] == '+')
{
temp1 = {};
for (j = 0; j < str_right.length(); j++)
{
if (str_right[j] >= 'A' && str_right[j] <= 'Z')
continue;
else
temp1 = temp1 + str_right[j];
}
break;
}
}
if (i == str_wrong.length()) //若没有 "+",则直接放入 temp1 内
temp1 = str_right;
for (i = 0; i < temp1.length(); i++) //求得最后结果
{
for (j = 0; j < str_wrong.length(); j++)
{
if (str_wrong[j] == temp1[i] || (str_wrong[j] >= 'A' && str_wrong[j] <= 'Z' && str_wrong[j] + 32 == temp1[i]))
break;
}
if (j == str_wrong.length())
temp2 = temp2 + temp1[i];
}
cout << temp2 << endl;
system("pause");
return 0;
}
023 旧键盘打字
最新推荐文章于 2023-03-12 21:03:21 发布