1033. 旧键盘打字(20)

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

输入格式:

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

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

输出格式:

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

输入样例:

7+IE.
7_This_is_a_test.

输出样例:

_hs_s_a_tst
#include<cstdio>
#include<cstring>
const int maxn = 100010;
char str[maxn];
bool HashTable[256];
int main(){
    memset(HashTable,true,sizeof(HashTable));
    gets(str);
    int len = strlen(str);
    for(int i = 0; i < len; i++){
        if(str[i] >= 'A' && str[i] <= 'Z'){
            str[i] = str[i] - 'A' + 'a';
        }
        HashTable[str[i]] = false;
    }
    gets(str);
    len = strlen(str);
    for(int i = 0; i < len; i++){
        if(str[i] >= 'A' && str[i] <= 'Z'){
            int low = str[i] - 'A' + 'a';
            if(HashTable[low] == true && HashTable['+']==true){
                printf("%c",str[i]);
            }
        }else if(HashTable[str[i]] == true){
            printf("%c",str[i]);
        }
    }
    printf("
");
    return 0;
}
//第三个测试点未通过,待验证
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
const int maxn = 100010;

int main(){
    bool hashTable[270];
    memset(hashTable,true,sizeof(hashTable));     
    char str1[maxn],str2[maxn];
    cin >> str1 >> str2;
    int len1 = strlen(str1);
    int len2 = strlen(str2);
    for(int i = 0 ; i < len1; i++){
        if(str1[i] >= 'A' && str1[i] <= 'Z')
           str1[i] = str1[i] - 'A' + 'a';
        hashTable[str1[i]] = false;
    }
    bool flag = false;
    for(int i = 0; i < len2; i++){
        if(str2[i] >= 'A' && str2[i] <= 'Z'){
            int low = str2[i] - 'A' + 'a';
            if(hashTable['+'] == true && hashTable[low] == true){
                printf("%c",str2[i]);
                flag = true;
            }            
        }else if(hashTable[str2[i]] == true){
            printf("%c",str2[i]);
            flag = true;
        }        
    }
    if(!flag) printf("
"); 
    return 0;
}
原文地址:https://www.cnblogs.com/wanghao-boke/p/8644802.html