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

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

  • 相关阅读:
    [Lydsy1706月赛]大根堆
    某考试 T1 Function
    [SHOI2016] 随机序列
    某考试 T1 至危警告
    某考试 T2 yja
    bzoj1880 [Sdoi2009]Elaxia的路线
    bzoj1804 [Ioi2007]Flood 洪水
    bzoj4546 codechef XRQRS
    bzoj4547 小奇的集合
    bzoj1443 [JSOI2009]游戏Game
  • 原文地址:https://www.cnblogs.com/cunyusup/p/10780487.html
Copyright © 2011-2022 走看看