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=;i < s.size();i++){
if(s[i] >= 'a'&&s[i] <= 'z'){
s[i] = s[i]-;
}
}
} int main(){
string s1;
string s2;
cin >> s1 >> s2;transferrr(s1);transferrr(s2); map<char,int> mp;
int i=,j=;
while(i < s1.size()&&j < s2.size()){
if(s1[i]!=s2[j]){
if(!mp[s1[i]]){ //未访问过
mp[s1[i]] = ;
cout << s1[i];
}
i++;
}
else {
i++;j++;
}
}
if(i < s1.size()){
for(;i < s1.size();i++){
if(!mp[s1[i]]){ //未访问过
mp[s1[i]] = ;
cout << s1[i];
}
}
} return ;
}

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

7_This_is_a_testx
_hs_s_a_es

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

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

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

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

PAT 1084 Broken Keyboard的更多相关文章

  1. PAT 1084 Broken Keyboard[比较]

    1084 Broken Keyboard (20 分) On a broken keyboard, some of the keys are worn out. So when you type so ...

  2. pat 1084 Broken Keyboard(20 分)

    1084 Broken Keyboard(20 分) On a broken keyboard, some of the keys are worn out. So when you type som ...

  3. 1084. Broken Keyboard (20)【字符串操作】——PAT (Advanced Level) Practise

    题目信息 1084. Broken Keyboard (20) 时间限制200 ms 内存限制65536 kB 代码长度限制16000 B On a broken keyboard, some of ...

  4. 1084 Broken Keyboard (20 分)

    1084 Broken Keyboard (20 分) On a broken keyboard, some of the keys are worn out. So when you type so ...

  5. PAT Advanced 1084 Broken Keyboard (20) [Hash散列]

    题目 On a broken keyboard, some of the keys are worn out. So when you type some sentences, the charact ...

  6. 1084. Broken Keyboard (20)

    On a broken keyboard, some of the keys are worn out. So when you type some sentences, the characters ...

  7. PAT (Advanced Level) 1084. Broken Keyboard (20)

    简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...

  8. 【PAT甲级】1084 Broken Keyboard (20 分)

    题意: 输入两行字符串,输出第一行有而第二行没有的字符(对大小写不敏感且全部以大写输出). AAAAAccepted code: #define HAVE_STRUCT_TIMESPEC #inclu ...

  9. 1084. Broken Keyboard (20)-水题

    #include <iostream> #include <cstdio> #include <string.h> #include <algorithm&g ...

随机推荐

  1. caffe报错:cudnn.hpp:86] Check failed: status == CUDNN_STATUS_SUCCESS (3 vs. 0) CUDNN_STATUS_BAD_PARAM 原因

    在实际项目中出现的该问题,起初以为是cudnn版本的问题,后来才定位到在网络进行reshape操作的时候 input_layer->Reshape({(), input_layer->sh ...

  2. 41A

    #include <stdio.h> #include <string.h> #define MAXSIZE 105 int main() { char Berlandish[ ...

  3. java Quartz定时器任务与Spring 的实现

    1.xml配置 <?xml version="1.0" encoding="UTF-8"?><beans xmlns="http:/ ...

  4. hive使用动态分区时如果动态分区的字段存在空值的问题

    hive的数据是放到hdfs中,当我们的分区字段类型为string时,如果使用动态分区向表中插入数据,而动态分区的那个字段恰好为null或者空字符串,这样hive会为其选一个默认的分区,我们查数据时分 ...

  5. [ Python ] unittest demo

    # -*- coding: utf-8 -*- import unittest class MyUT(unittest.TestCase): def test_1(self): print(" ...

  6. GO格式化打印

    General(通用占位符)  Integer整形  Integer width(指定长度的整型,以5为例)  Float(浮点数)  String(字符串)  String Width ( ...

  7. phpstudy 安装 Apcahe SSL证书 实现https连接

    摘自:https://jingyan.baidu.com/article/64d05a022e6b57de54f73b51.html Windows phpstudy安装ssl证书教程. 工具/原料 ...

  8. 简单代码生成csv文件(excel)

    $arr = array('');// 目标数组 header("Content-Type:application/vnd.ms-excel;charset=gbk"); head ...

  9. 常见的python的unittest用法

    python的unittest好处是通过python脚本编写用例,每个用例可以单独调试初始化和清理动作,因为都是用例都是代码所以调试起来也很方便:它的缺点是得先学会python,难易程度见仁见智吧,对 ...

  10. jQuery 新建函数

    jQuery 新建函数 格式一: // 格式一:新建添加函数方法并使用 $.extend({ 'xsk':function () { return 'xsk'; } }); // 调用 $.xsk() ...