zoukankan      html  css  js  c++  java
  • PAT Advanced 1084 Broken Keyboard (20分)

    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;
    }
  • 相关阅读:
    js 控制页面跳转的5种方法
    弹性盒
    js中变量声明有var和没有var的区别
    解决Cannot read property 'style' of null中样式问题
    JS中用for循环解决重复定义的问题
    博客第一天
    jQuery 无缝轮播
    随鼠标移动
    倒计时
    轮播图
  • 原文地址:https://www.cnblogs.com/littlepage/p/12232889.html
Copyright © 2011-2022 走看看