PAT乙级-1033

题目

旧键盘上坏了几个键,于是在敲一段文字的时候,对应的字符就不会出现。现在给出应该输入的一段文字、以及坏掉的那些键,打出的结果文字会是怎样?
输入格式:
输入在2行中分别给出坏掉的那些键、以及应该输入的文字。其中对应英文字母的坏键以大写给出;每段文字是不超过105个字符的串。可用的字符包括字母[a-z, A-Z]、数字0-9、以及下划线“_”(代表空格)、“,”、“.”、“-”、“+”(代表上档键)。题目保证第2行输入的文字串非空。
注意:如果上档键坏掉了,那么大写的英文字母无法被打出。
输出格式:
在一行中输出能够被打出的结果文字。如果没有一个字符能被打出,则输出空行。
输入样例:
7+IE.
7_This_is_a_test.
输出样例:
_hs_s_a_tst

代码

#include 
using namespace std;
#include 
#include 
#include  

int main(int argc, char** argv) {   

    char wrong[100],s[100000];
    gets(wrong);
    gets(s);
    //错误字符分类 
    char alph[100000],other[100000];
    int flag=0,a_c=0,o_c=0;//flag判断是否能用大写
    for(int i=0; i<strlen(wrong); i++){
        if((wrong[i]>='a'&&wrong[i]<='z') || (wrong[i]>='A'&&wrong[i]<='Z')){
            alph[a_c++] = wrong[i];
        }else if(wrong[i] == '+'){
            flag=1;//表示不能输出大写字母 
        }else{
            other[o_c++] = wrong[i];
        }
    }
    //分组测试 
    for(int i=0; i<strlen(s); i++){     
        if((s[i]>='A' && s[i]<='Z') || (s[i]>='a' && s[i]<='z')){//字母 
            int f_alph = 1;
            for(int j=0; j<strlen(alph); j++){
                if(s[i]>='A' && s[i]<='Z' && flag){
                    f_alph = 0;
                    break;
                }else if(s[i] == alph[j]+32){
                    f_alph = 0;
                    break;
                }

            }
            if(f_alph) cout<else{
            int f_other = 1;
            for(int j=0; j<strlen(other); j++){
                if(s[i] == other[j]){
                    f_other = 0;
                    break;
                }
            }
            if(f_other) cout<return 0;
}

暂且还有错误:
PAT乙级-1033_第1张图片

你可能感兴趣的:(PAT)