PAT训练-1033. 旧键盘打字(20)

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

输入格式:

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

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

输出格式:

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

输入样例:

7+IE.
7_This_is_a_test.

输出样例:

_hs_s_a_tst

注意:由于第一行可能为空,所以应考虑gets和getline来处理,否则测试点2无法通过,其次就是我先尝试了gets处理字符数字,发现最后一个测试点会超时,因此后面选择用getline
代码:

//

//  main.cpp

//  test

#include <iostream>

#include <queue>

#include <iomanip>

#include <math.h>

#include <vector>

#include <string>

#include <algorithm>

#include <map>

#include<cstring>

#include<ctype.h>

using namespace std;

int main(int argc, const char * argv[]) {

    map<char, int> badpool;

//    for(char temp = ‘A’;temp<=’Z’;temp++)

//    {

//        badpool[temp] = 0;

//    }

//    for(char temp = ‘0’;temp<=’9′;temp++)

//    {

//        badpool[temp] = 0;

//    }

//    badpool[‘_’] = 0;

//    badpool[‘,’] = 0;

//    badpool[‘.’] = 0;

//    badpool[‘-‘] = 0;

//    badpool[‘+’] = 0;

//    char bad[100000];

//    gets(bad);

    string bad;

    getline(cin, bad);

    for(int i = 0 ; i < bad.size();i++)

    {

        badpool[bad[i]] =1 ;

    }

    string Catch;

    getline(cin, Catch);

    for(int i = 0 ; i < Catch.size();i++)

    {

        if(Catch[i]>=‘a’&&Catch[i]<=‘z’)

        {

            if(badpool[Catch[i]+‘A’‘a’]!=1)

                printf(“%c”,Catch[i]);

                //cout<<Catch[i];

        }else if(Catch[i]>=‘A’&&Catch[i]<=‘Z’)

        {

            if(badpool[Catch[i]]!=1)

                if(badpool[‘+’]!=1)

                    printf(“%c”,Catch[i]);

//                    cout<<Catch[i];

        }else

        {

            if(badpool[Catch[i]]!=1)

                printf(“%c”,Catch[i]);

                //cout<<Catch[i];

        }

    }

    cout<<endl;

    

    

}

发表评论