码迷,mamicode.com
首页 > 其他好文 > 详细

PAT Advanced 1084 Broken Keyboard (20分)

时间:2020-01-25 11:41:55      阅读:76      评论:0      收藏:0      [点我收藏+]

标签:file   order   color   Once   cli   case   upper   list   present   

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;
}

 

PAT Advanced 1084 Broken Keyboard (20分)

标签:file   order   color   Once   cli   case   upper   list   present   

原文地址:https://www.cnblogs.com/littlepage/p/12232889.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!