您的位置:首页 > 编程语言 > C语言/C++

PAT:B1033. 旧键盘打字(16/20)

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

输入格式:

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

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

输出格式:

在一行中输出能够被打出的结果文字。如果没有一个字符能被打出,则输出空行。
输入样例:
7+IE.
7_This_is_a_test.

输出样例:

_hs_s_a_tst

#include <stdio.h>
#include <cstring>
using namespace std;
bool state[50] = { false };

int main() {
char str1[50];
scanf("%s", str1);
//printf("%d\n", strlen(str1));
for (int i = 0; i < strlen(str1); i++)
{
if (str1[i]>='a'&&str1[i]<='z'){
state[str1[i] - 'a'] = true;
}else if (str1[i]>='A'&&str1[i]<='Z')
{
state[str1[i] - 'A'] = true;
}
else if(str1[i]>='0'&&str1[i]<='9')
{
state[str1[i]-'0'+31]=true;
}
else if(str1[i]=='_')
{
state[str1[i] - '_' + 26] = true;
}
else if (str1[i] == ',') {
state[str1[i] - ',' + 27] = true;
}
else if (str1[i] == '.') {
state[str1[i] - '.' + 28] = true;
}
else if (str1[i] == '-') {
state[str1[i] - '-' + 29] = true;
}
else
{
state[30] = true;
}
}
char temp;
char str2[100010];
scanf("%s",str2);
for(int i=0;i<=strlen(str2);i++){
temp=str2[i];
if ((temp>='a'&&temp<='z')&&(state[temp-'a']==true))
{
continue;
}
else if((temp>='A'&&temp<='Z')&&(state[temp-'A']==true))
{
continue;
}
else if ((temp >= 'A'&&temp <= 'Z') && (state[30] == true))
{
continue;
}
else if (temp == '_'&&state[temp - '_' + 26] == true)
{
continue;
}
else if (temp == ','&&state[temp - ',' + 27] == true)
{
continue;
}
else if (temp == '.'&&state[temp - '.' + 28] == true)
{
continue;
}
else if (temp == '-'&&state[temp - '-' + 29] == true)
{
continue;
}
else if(temp>='0'&&temp<='9'&&state[temp-'0'+31]==true)
{
continue;
}
else
{
printf("%c", temp);
continue;
}
}
printf("\n");
return 0;
}


有一个1′运行错误,和一个3′运行超时。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  PAT 乙级 C++ c语言