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中的都是坏的按键)

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

  • 相关阅读:
    随机生成一份试卷,试卷的种类分为单选、多选、判断三种题型。nodejs6.0 mysql
    git 常用命令
    ECMAScript 继承机制实现
    javascript正则表达式
    利用javascript实现二维数组的筛选
    iframe引入百度地图显示企业位置
    前端开发APP,从HBuilder开始~
    js闭包理解
    Python多线程threading与多线程中join()的用法
    Python中的装饰器
  • 原文地址:https://www.cnblogs.com/cunyusup/p/10780487.html
Copyright © 2011-2022 走看看