ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

PAT Advanced 1084 Broken Keyboard (20分)

2020-01-25 11:57:30  阅读:231  来源: 互联网

标签:case 1084 20 string str1 contains worn Broken out


On a broken keyboard, some of the keys are worn out. So when you type some sentences, the characters corresponding to those keys will not appear on screen.

Now given a string that you are supposed to type, and the string that you actually type out, please list those keys which are for sure worn out.

Input Specification:

Each input file contains one test case. For each case, the 1st line contains the original string, and the 2nd line contains the typed-out string. Each string contains no more than 80 characters which are either English letters [A-Z] (case insensitive), digital numbers [0-9], or _ (representing the space). It is guaranteed that both strings are non-empty.

Output Specification:

For each test case, print in one line the keys that are worn out, in the order of being detected. The English letters must be capitalized. Each worn out key must be printed once only. It is guaranteed that there is at least one worn out key.

Sample Input:

7_This_is_a_test
_hs_s_a_es
 

Sample Output:

7TI

坏键盘,乙级碰到过,我们在进行检测的时候

读入串

进行遍历第一个串,转大写后映射到map。

进行遍历第二个串,进行映射到map为false。

进行遍历第一个串,进行映射到map为false,并且打印。

#include <iostream>
#include <unordered_map>
using namespace std;
int main(){
    string str1, str2;
    unordered_map<char, bool> m;
    getline(cin, str1);
    getline(cin, str2);
    for(int i = 0; i < str1.length(); i++)
        m[toupper(str1[i])] = true;
    for(int i = 0; i < str2.length(); i++)
        m[toupper(str2[i])] = false;
    for(int i = 0; i < str1.length(); i++)
        if(m[toupper(str1[i])]) {
            cout << (char)toupper(str1[i]);
            m[toupper(str1[i])] = false;
        }
    system("pause");
    return 0;
}

 

标签:case,1084,20,string,str1,contains,worn,Broken,out
来源: https://www.cnblogs.com/littlepage/p/12232889.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有