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 ...
随机推荐
- [LeetCode] 62. Unique Paths_ Medium tag: Dynamic Programming
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The ...
- mysql 日期相关 CURRENT_TIMESTAMP, CURRENT_DATE, CURRENT_TIME
MySQL 时间函数 SELECT CURRENT_TIMESTAMP, CURRENT_DATE, CURRENT_TIME, CURRENT_TIME(), NOW(); https://dev. ...
- python相关学习文档收集
bs4中文文档: 用于网页爬虫 https://beautifulsoup.readthedocs.io/zh_CN/v4.4.0/ GitLab-CI 从安装到差点放弃 https://segm ...
- nginx----------nginx日志详细分解
1.客户端(用户)IP地址.如:上例中的 47.52.45.228 2.访问时间.如:上例中的 [03/Jan/2013:21:17:20 -0600] 3.请求方式(GET或者POST等).如:上例 ...
- SV coverage
covergroup是对coverage model的一种包装,每个covergroup可以包含: 1) sync event来触发采样, 2) 很多coverpoint, 3) cross cove ...
- [转][访谈] Olivier Grisel谈scikit-learn和机器学习技术的未来
原文:http://www.csdn.net/article/2015-10-11/2825882 几周前,我们的Florian Douetteau (FD)对Olivier Grisel(OG)进行 ...
- git help 机器翻译
该篇发布仅为博主个人保存并参考,内容可能不对 usage: git [--version] [--help] [-C <path>] [-c <name>=<value& ...
- 一个简单好用的日志框架NLog
之前我介绍过如何使用log4net来记录日志,但最近喜欢上了另一个简单好用的日志框架NLog. 关于NLog和log4net的比较这里就不多讨论了,感兴趣的朋友可以参看.NET日志工具介绍和log4n ...
- IDEA 自动重新载入
IDEA 自动重新载入: Ctrl + F9
- mybatis源码解析12---ResultSetHandler解析
说完了StatementHandler和ParameterHandler,接下来就需要对查询的结果进行处理了,而对于sql结果的处理是由ResultSetHandler处理的,ResultHandle ...