PAT (Basic Level) Practice (中文)1033 旧键盘打字 (20 分)

时间:2022-07-26
本文章向大家介绍PAT (Basic Level) Practice (中文)1033 旧键盘打字 (20 分),主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

1033 旧键盘打字 (20 分)

旧键盘上坏了几个键,于是在敲一段文字的时候,对应的字符就不会出现。现在给出应该输入的一段文字、以及坏掉的那些键,打出的结果文字会是怎样?

输入格式:

输入在 2 行中分别给出坏掉的那些键、以及应该输入的文字。其中对应英文字母的坏键以大写给出;每段文字是不超过 10​5​​ 个字符的串。可用的字符包括字母 [a-z, A-Z]、数字 0-9、以及下划线 _(代表空格)、,.-+(代表上档键)。题目保证第 2 行输入的文字串非空。

注意:如果上档键坏掉了,那么大写的英文字母无法被打出。

输出格式:

在一行中输出能够被打出的结果文字。如果没有一个字符能被打出,则输出空行。

输入样例:

7+IE.
7_This_is_a_test.

输出样例:

_hs_s_a_tst

两种情况:上档键坏掉,所有大写字母不能打出;单个大写字母不能打出;

分情况讨论,其他模拟即可~

// luogu-judger-enable-o2
#include<bits/stdc++.h>
#include<unordered_set>
#define rg register ll
#define inf 2147483647
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
#define ll long long
#define maxn 300005
#define lb(x) (x&(-x))
const double eps = 1e-6;
using namespace std;
inline ll read()
{
	char ch = getchar(); ll s = 0, w = 1;
	while (ch < 48 || ch>57) { if (ch == '-')w = -1; ch = getchar(); }
	while (ch >= 48 && ch <= 57) { s = (s << 1) + (s << 3) + (ch ^ 48); ch = getchar(); }
	return s * w;
}
inline void write(ll x)
{
	if (x < 0)putchar('-'), x = -x;
	if (x > 9)write(x / 10);
	putchar(x % 10 + 48);
}
string a,b;
set<char>p;
int main()
{
    getline(cin,a);
    getline(cin,b);
    bool flag=0;
    for(rg i=0;a[i];i++)
    {
        if(a[i]=='+')flag=1;
        else
        {
            if(a[i]>='A'&&a[i]<='Z')p.insert(a[i]),a[i]+=32;
            //if(a[i]=='_')a[i]=' ';
            p.insert(a[i]);
        }
    }
    for(rg i=0;b[i];i++)
    {
        if(p.find(b[i])!=p.end())
        {
            continue;
        }
        if(flag==1&&(b[i]>='A'&&b[i]<='Z'))continue;
        cout<<b[i];
    }
   	return 0;
}