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. JDBC 和连接池

    1 JDBC概述 Java DataBase Connectivity,Java数据库连接,一种执行SQL的Java API,为多种关系数据库提供统一访问规范,由一组Java语言编写的类和接口组成.数 ...

  2. .net core使用ef core操作mysql数据库

    新建.net core webapi项目 在NuGet包管理器中搜索 MySql.Data.EntityFrameworkCore并安装,安装的8.0.14版本,只安装这一个就够了 安装后创建Data ...

  3. JAVA的值传递问题

    为什么 Java 中只有值传递? 首先回顾一下在程序设计语言中有关将参数传递给方法(或函数)的一些专业术语.按值调用(call by value)表示方法接收的是调用者提供的值,而按引用调用(call ...

  4. CentOS 7 MariaDB-MHA

    关于MHA    MHA(Master High Availability)是一款开源的mysql高可用程序,目前在mysql高可用方面是一个相对成熟的解决方案.MHA 搭建的前提是MySQL集群中已 ...

  5. mecacheq的配置

    在处理业务逻辑时有可能遇到高并发问题,例如商城秒杀.微博评论等.如果不做任何措施可能在高瞬间造成服务器瘫痪,如何解决这个问题呢?队列是个不错的选择.队列(Queue)又称先进先出(First In F ...

  6. Zookeeper 3.5启动时 8080端口被占用

    今天闲来无事,学习Zookeeper,下载了Zookeeper的最新版本3.5.启动以后显示: ZooKeeper JMX enabled by default Using config: /opt/ ...

  7. 大堆文字不如几张图片-论信息传递的方式以NodeMCU入门为例

  8. Flask最强攻略 - 跟DragonFire学Flask - 第十四篇 Flask-SQLAlchemy

    前不久刚刚认识过了SQLAlchemy,点击这里复习一下 当 Flask 与 SQLAlchemy 发生火花会怎么样呢? Flask-SQLAlchemy就这么诞生了 首先要先安装一下Flask-SQ ...

  9. Java 创建文本内容

    Java 创建文本内容 import java.io.FileWriter; import java.io.IOException; public class TestFile { public st ...

  10. Linux下执行Oracle的sql脚本

    (1)  启动监听: Root用户登录后,输入: $su – oracle 回车(Oracle为Oracle数据库安装用户,必须有横杠: - ) 启动监听: $lsnrctl start --启动 $ ...