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. py三个面试小问题

    1.是否遇到过Python的模块间循环引用的问题,如何避免它? 这是代码结构设计的问题,模块依赖和类依赖,如果老是觉得碰到循环引用可能的原因有几点: a.可能是模块的分界线划错地方了 b.可能是把应该 ...

  2. springmvc.xml 中 <url-pattern></url-pattern>节点详解

    1.  先来上段常见的代码 <!-- MVC Servlet --> <servlet> <servlet-name>springServlet</servl ...

  3. node 解析图片二维码的内容

    const {readFile, readFileSync} = require('fs'); const decodeImage = require('jimp').read; const qrco ...

  4. IDEA eclipse转maven

    在pom.xml 文件上右键 Add as Maven Project

  5. 实现html页面自动刷新的几种方式

    自动页面刷新通常会用在对数据的实时性比较敏感的网站中,比如股票走势等,另外在普通的页面自动跳转中也会使用到页面自动刷新技术. 页面刷新我见过的有三种方式,下面来一一说明 1.通过在<head&g ...

  6. kafka消费者实时消费数据存入hdfs java scalca 代码

    hadoop-client依赖很乱 调试很多次cdh版本好多jar没有 用hadoop2.7.3可以 自定义输出流的池子进行流管理 public void writeLog2HDFS(String p ...

  7. 复习-css控制文本字体属性

    css控制文本字体属性 font-family:字体系列,如”serif“”sans-serif“ font-size:尺寸 font-style:字体样式,如“normal,italic(斜体).o ...

  8. CSS Class 选择器

    CSS Class 选择器 再<stype>标签内,通过class属性来对标签进行css样式配置 <html> <head> <!-- style 设置头部标 ...

  9. Docker Macvlan 介绍 or 工作原理

    Docker Macvlan Network Macvlan Network:属于Docker的网络驱动. Macvlan Network:Docker主机网卡接口逻辑上分为多个子接口,每个子接口标识 ...

  10. pip使用豆瓣的镜像源

    豆瓣镜像地址:https://pypi.douban.com/simple/ 虽然用easy_install和pip来安装第三方库很方便 它们的原理其实就是从Python的官方源pypi.python ...