旧键盘

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

输入格式:

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

输出格式:

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

输入样例:

7_This_is_a_test
_hs_s_a_es

输出样例:

7TI

#include<iostream>
#include<string>

using namespace std;
int main() {
    string str,str1;//输入输入的字符串和输出的字符串
    cin >> str >> str1;
    int a[58] = { 0 };

    for (int i = 0; i < int(str.size()); i++) {
        int tag = 0;
        for (int j = 0; j < int(str1.size()); j++) {
            if (str[i] == str1[j]) {
                tag++;
                break;
            }//检查输入字符串中的某个元素输出字符串里是否包含
        }
        if (tag == 0) {
            if (str[i] >= 97) {
                if (a[str[i] - 'a'] == 0) {
                    a[str[i] - 'a']++;
                    int aq = str[i] - 32;//转换成大写
                    cout << (char)aq;//将数字转换成对应的ASSCII码输出
                }
            }//字母为大写的时候
            else if (str[i] >= 65) {
                if (a[str[i] - 'A'] == 0) {//前面没有输出这个单词的大小写时
                    a[str[i] - 'A']++;//要输出大写,标记一下
                    cout << str[i];//输出
                }
            }//字母为小写的时候
            else {
                if (a[str[i]] == 0) {
                    a[str[i]]++;//当为数字的时候
                    cout << str[i];
                }
            }
        }
    }
}

猜你喜欢

转载自blog.csdn.net/qq_42082542/article/details/84575819