zoukankan      html  css  js  c++  java
  • PAT 1084 Broken Keyboard

    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
    
    作者: CHEN, Yue
    单位: 浙江大学
    时间限制: 200 ms
    内存限制: 64 MB
    代码长度限制: 16 KB
     
     
    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    
    void transferrr(string &s){
        for(int i=0;i < s.size();i++){
            if(s[i] >= 'a'&&s[i] <= 'z'){
                s[i] = s[i]-32;
            }
        }
    }
    
    
    
    
    int main(){
        string s1;
        string s2;
        cin >> s1 >> s2;transferrr(s1);transferrr(s2);
    
        map<char,int> mp;
        int i=0,j=0;
        while(i < s1.size()&&j < s2.size()){
            if(s1[i]!=s2[j]){
                if(!mp[s1[i]]){ //未访问过
                    mp[s1[i]] = 1;
                    cout << s1[i];
                }
                i++;
            }
            else {
                i++;j++;
            }
        }
        if(i < s1.size()){
            for(;i < s1.size();i++){
                if(!mp[s1[i]]){ //未访问过
                    mp[s1[i]] = 1;
                    cout << s1[i];
                }
            }
        }
    
    
        return 0;
    }

    ——一开始漏掉了i还未访问完的测试点:

    7_This_is_a_testx
    _hs_s_a_es

    ——最好的思路(网上的):

    用map记录s2(都是完好的按键)

    然后遍历s1(不在map中的都是坏的按键)

     ——不一定每个人都能想出最好的方法,考场上只要能得分就行

  • 相关阅读:
    利用正则表达式,完成参数的替换
    使用python读取yaml文件
    python+unittet在linux与windows使用的区别
    python发送requests请求时,使用登录的token值,作为下一个接口的请求头信息
    jmeter线程组之间传参
    requests:json请求中中文乱码处理
    ddt源码修改:HtmlTestRunner报告依据接口名显示用例名字
    使用openpyxl的styles,实现写入值时加背景色
    批量数据请求接口
    locust参数化
  • 原文地址:https://www.cnblogs.com/cunyusup/p/10780487.html
Copyright © 2011-2022 走看看