1033. 旧键盘打字(20)
时间限制
200 ms
内存限制
65536 kB
代码长度限制
8000 B
判题程序
Standard
作者
CHEN, Yue
旧键盘上坏了几个键,于是在敲一段文字的时候,对应的字符就不会出现。现在给出应该输入的一段文字、以及坏掉的那些键,打出的结果文字会是怎样?
输入格式:
输入在2行中分别给出坏掉的那些键、以及应该输入的文字。其中对应英文字母的坏键以大写给出;每段文字是不超过105个字符的串。可用的字符包括字母[a-z, A-Z]、数字0-9、以及下划线“_”(代表空格)、“,”、“.”、“-”、“+”(代表上档键)。题目保证第2行输入的文字串非空。
注意:如果上档键坏掉了,那么大写的英文字母无法被打出。
输出格式:
在一行中输出能够被打出的结果文字。如果没有一个字符能被打出,则输出空行。
输入样例:7+IE. 7_This_is_a_test.输出样例:
_hs_s_a_tst
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<set>
#include<string>
#include<vector>
using namespace std;
int main()
{
string s1, s2;
//cin >> s1 >> s2;
getline(cin, s1);//getline和gets可读入空行,以'\n'结束
getline(cin,s2);
int j;
j = 0; int pos;
if (s1 == "")
cout << s2 << endl;
else
{
while (s2[j] != '\0')
{
do
{
if (s2[j] >= 'a'&&s2[j] <= 'z')
pos = s1.find(s2[j] - 'a' + 'A');
else if (s2[j] >= 'A'&&s2[j] <= 'Z')
{
pos = s1.find(s2[j]);//这个地方要注意,发现字母键没坏,但还要检查‘+’
if(pos<0)
pos = s1.find('+');
}
else
pos = s1.find(s2[j]);
if (pos >= 0)
{
s2.replace(j, 1, "");
}
} while (pos >= 0);//因为把字符去掉后,j所指对象改变为后一位,必须继续进行
if (s2[j] == '\0')
break;
j++;
}
cout << s2 << endl;;
}
return 0;
}