PAT-BASIC-1029-旧键盘

旧键盘上坏了几个键,于是在敲一段文字的时候,对应的字符就不会出现。现在给出应该输入的一段文字、以及实际被输入的文字,请你列出肯定坏掉的那些键。

输入格式:

输入在2行中分别给出应该输入的文字、以及实际被输入的文字。每段文字是不超过80个字符的串,由字母A-Z(包括大、小写)、数字0-9、以及下划线“_”(代表空格)组成。题目保证2个字符串均非空。

输出格式:

按照发现顺序,在一行中输出坏掉的键。其中英文字母只输出大写,每个坏键只输出一次。题目保证至少有1个坏键。

输入样例:

7_This_is_a_test
_hs_s_a_es

输出样例:

7TI

逐个比较,当src串出现有而des串中没有出现的,就是对应的坏键...
用一个map记录已经出现的坏键

#include <bits/stdc++.h>
using namespace std;

string src, des;
int lenSrc, lenDes;
map<char, bool> chTable;
int  main(){
    cin >> src;
    lenSrc = src.length();
    cin >> des;
    lenDes = des.length();
    int i = 0, j = 0;
    while(i < lenSrc){
        if(src[i] != des[j]){
            if(isdigit(src[i])){
                if(!chTable[src[i]]){
//                    cout << src[i];
                    printf("%c", src[i]);
                    chTable[src[i]] = true;
                }
            }
            else{
                if(!chTable[toupper(src[i])]){
//                    cout << toupper(src[i]);
                    printf("%c", toupper(src[i]));
                    chTable[toupper(src[i])] = true;
                }
            }
            ++i;
        }
        else{
            ++i;
            ++j;
        }
    }
    return 0;
}
CAPOUIS'CODE

 

posted @ 2015-07-13 16:56  CAPOUIS  阅读(145)  评论(0)    收藏  举报