旧键盘上坏了几个键,于是在敲一段文字的时候,对应的字符就不会出现。现在给出应该输入的一段文字、以及实际被输入的文字,请你列出肯定坏掉的那些键。
输入格式:
输入在 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;const int N = 100;
int vis[N];int main()
{string s1;string s2;cin >> s1 >> s2;for (int i = 0; i < s1.length(); i++){if (s1[i] >= 'a' && s1[i] <= 'z') s1[i] = s1[i] - 'a' + 'A';vis[s1[i]]++;}for (int i = 0; i < s2.length(); i++){if (s2[i] >= 'a' && s2[i] <= 'z') s2[i] = s2[i] - 'a' + 'A';vis[s2[i]]--;}for (int i = 0; i < s1.length(); i++){if (vis[s1[i]] > 0){vis[s1[i]] = 0;cout << s1[i];}}return 0;
}
代码如下:
#include <iostream>
#include <string>
#include <vector>
using namespace std;
const int N = 300;
bool vis[N] = { 0 };
vector<char> v;int main()
{string s1;string s2;cin >> s1 >> s2;int idx1 = 0;int idx2 = 0;int len1 = s1.length();int len2 = s2.length();while (idx1 < len1 && idx2 < len2){if (s1[idx1] != s2[idx2]){if ((int)s1[idx1] >= 'a' && (int)s1[idx1] <= 'z' && !vis[s1[idx1]]){vis[s1[idx1]] = true;vis[s1[idx1] - 32] = true;v.push_back(s1[idx1]);}else if ((int)s1[idx1] >= 'A' && (int)s1[idx1] <= 'Z' && !vis[s1[idx1]]){vis[s1[idx1]] = true;vis[s1[idx1] + 32] = true;v.push_back(s1[idx1]);}else if (!vis[s1[idx1]]){v.push_back(s1[idx1]);vis[s1[idx1]] = true;}idx1++;}else{idx1++;idx2++;}}while (idx1 < len1){if ((int)s1[idx1] >= 'a' && (int)s1[idx1] <= 'z' && !vis[s1[idx1]]){vis[s1[idx1]] = true;vis[s1[idx1] - 32] = true;v.push_back(s1[idx1]);}else if ((int)s1[idx1] >= 'A' && (int)s1[idx1] <= 'Z' && !vis[s1[idx1]]){vis[s1[idx1]] = true;vis[s1[idx1] + 32] = true;v.push_back(s1[idx1]);}else if (!vis[s1[idx1]]){v.push_back(s1[idx1]);vis[s1[idx1]] = true;}idx1++;}for (vector<char>::iterator it = v.begin(); it != v.end(); it++){if ((int)*it >= 'a' && (int)*it <= 'z')cout <<(char) (*it-32);else cout << *it;}cout << endl;return 0;
}