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

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

  • 相关阅读:
    几个有用的jQuery方法
    Highcharts常用属性的说明
    存储过程中判断临时表是否已经存在方法
    解决Dialog中EditView无法触发软键盘问题
    mysql数据库备份与恢复
    Ubuntu 安装 sunjava6jdk 错误解决办法
    putty关闭后后让java程序在后台一直执行
    jni数据类型
    android 打开各种文件(setDataAndType)
    防止Linux出现大量FIN_WAIT1
  • 原文地址:https://www.cnblogs.com/cunyusup/p/10780487.html
Copyright © 2011-2022 走看看