PAT 1084 Broken Keyboard
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
#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的更多相关文章
- PAT 1084 Broken Keyboard[比较]
1084 Broken Keyboard (20 分) On a broken keyboard, some of the keys are worn out. So when you type so ...
- 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 ...
- 1084. Broken Keyboard (20)【字符串操作】——PAT (Advanced Level) Practise
题目信息 1084. Broken Keyboard (20) 时间限制200 ms 内存限制65536 kB 代码长度限制16000 B On a broken keyboard, some of ...
- 1084 Broken Keyboard (20 分)
1084 Broken Keyboard (20 分) On a broken keyboard, some of the keys are worn out. So when you type so ...
- 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 ...
- 1084. Broken Keyboard (20)
On a broken keyboard, some of the keys are worn out. So when you type some sentences, the characters ...
- PAT (Advanced Level) 1084. Broken Keyboard (20)
简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...
- 【PAT甲级】1084 Broken Keyboard (20 分)
题意: 输入两行字符串,输出第一行有而第二行没有的字符(对大小写不敏感且全部以大写输出). AAAAAccepted code: #define HAVE_STRUCT_TIMESPEC #inclu ...
- 1084. Broken Keyboard (20)-水题
#include <iostream> #include <cstdio> #include <string.h> #include <algorithm&g ...
随机推荐
- docker容器的操作
容器操作 1.查看本地容器 docker ps -a # 查看所有容器 docker ps # 查看所有正在运行的容器 2.容器的创建与启动 方法一:两步完成(强烈推荐方法)(1)创建 docker ...
- 001-CPU多级缓存架构
一.基本概念 大致关系: CPU Cache --> 前端总线 FSB (下图中的Bus) --> Memory 内存 CPU 为了更快的执行代码.于是当从内存中读取数据时,并不是只读自己 ...
- dubbo注册到zookeeper
zk注册中心安装,参见dubbo官网:http://dubbo.apache.org/books/dubbo-admin-book/install/zookeeper.html provider.xm ...
- ch01 PHP开篇
ch01 PHP开篇 1.1启蒙知识 思考:WAMP是什么?:集成开发环境 [Windows+Apache服务器+MySQL数据库+PHP编程] 1.1.1 站点 将网站所有相关素材都放到一个文件夹中 ...
- 152. Maximum Product Subarray(动态规划)
Given an integer array nums, find the contiguous subarray within an array (containing at least one n ...
- -bash: 未预期的符号 `(' 附近有语法错误
[1]问题现象 -bash: 未预期的符号 `(' 附近有语法错误 [2]解决方案 给括号前面加反斜杠即可 Good Good Study, Day Day Up. 顺序 选择 循环 总结
- JVM内存结构分析
对于Java程序员来说,内存是由JVM自动管理的,所以一旦出现内存泄漏或溢出的问题,不了解JVM的内存结构和各个内存区域的工作职责,将对解决问题带来很大的麻烦,本文参照周志明的<深入理解Java ...
- 创建servlet程序知识点详解---servlet-day05
jdbc.properties怎么写? 把秘密改为自己电脑设置的 password url 3306 是安装mysql时所确定的端口 后面还可以接字符集的限定 #1 jsp是什么?(java ser ...
- 微信小程序之mpvue+iview踩坑之旅
因为之前参照微信的原生的文档写过一些小程序的demo,写的过程比较繁琐,后来出了美团的mpvue,可以直接使用vue开发,其他的不作对比,这篇文章记录一下踩坑之旅. 参照mpvue http://mp ...
- jquery改变字符串中部分字符的颜色
//该方法改变字符串中中括号内(包括中括号)的字符串颜色为红色function changecolocer() { var zf = $('#YWFA').text(); if(zf.length&g ...