题目例如以下:

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

题目的实质就是从A字符串中找到全部B中没有的。然后输出。注意要把字母转为大写,而且反复的仅仅输出一次。输出顺序为与从前到后探測到的顺序同样。

由于不区分大写和小写,所以我们使用一个map存储全部实际输出的字符,然后遍历期望的字符串,假设遍历到的字符是字母,先转为大写,然后去map查询,假设查不到则说明是要输出的。而且存储map,这样就保证了不反复输出,也满足了输出顺序和大写。

代码例如以下:

#include <iostream>
#include <string>
#include <map>
#include <stdio.h>using namespace std;int main()
{string wanner,input;cin >> wanner >> input;map<char,bool> inputMap;for(int i = 0; i < input.length(); i++){input[i] = isalpha(input[i]) ? toupper(input[i]) : input[i];inputMap[input[i]] = true;}for(int i = 0; i < wanner.length(); i++){char c = wanner[i];c = isalpha(c) ? toupper(c) : c;if(inputMap.find(c) == inputMap.end()){inputMap[c] = true;printf("%c",c);}}return 0;
}

1084. Broken Keyboard (20)相关推荐

  1. 【简便解法】1084 Broken Keyboard (20 分)_16行代码AC

    立志用最少的代码做最高效的表达 PAT甲级最优题解-->传送门 On a broken keyboard, some of the keys are worn out. So when you ...

  2. 【PAT甲级 删除字符串中重复字母】1084 Broken Keyboard (20 分) Java 全部AC

    题目 题解 Java import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamRead ...

  3. PAT甲级1084 Broken Keyboard:[C++题解]字符串处理、双指针算法

    文章目录 题目分析 题目来源 题目分析 来源:acwing ac代码1:双指针算法 读入两个字符串a和b,用两个指针i和j分别遍历a.b.如果a[i] ==b[j],说明键盘没坏,j往后移动一个:如果 ...

  4. PAT Broken Keyboard (20)

    题目描写叙述 On a broken keyboard, some of the keys are worn out. So when you type some sentences, the cha ...

  5. 1084 Broken Keyboard

    两个注意的点 1.本题被归到散列专题下,但是由于是逐字符地映射到整形,可以直接把布尔型哈希数组的大小设置为ASCII的数量128,然后直接将字符作为数组下标(如果是字符串,才需要自己写一个哈希函数,将 ...

  6. UVa11988-破损的键盘 Broken Keyboard

    题目描述 You're typing a long text with a broken keyboard. Well it's not so badly broken. The only probl ...

  7. 1112. Stucked Keyboard (20)

    1112. Stucked Keyboard (20) 注:如果存在这样的字符串,sss_sssaedsss_s,那么我们认为s是好键(次数为3),所以,在一开始,我们第一次访问的时候,不能马上确定哪 ...

  8. 例题6-4 破损的键盘(又名:悲剧文本)(Broken Keyboard(a.k.a. Beiju Text), UVa 11988)

    例题6-4 破损的键盘(又名:悲剧文本)(Broken Keyboard(a.k.a. Beiju Text), UVa 11988) 链表的应用 #include<iostream> # ...

  9. Broken Keyboard (a.k.a. Beiju Text)

    原题及翻译 Broken Keyboard (a.k.a. Beiju Text) 破碎的键盘(a.k.a. Beiju Text) You're typing a long text with a ...

最新文章

  1. SpriteBuilder中如何平均拉伸精灵帧动画的距离
  2. 解决gcc报错:error: implicit declaration of function ‘inet_addr’ [-Werror=implicit-function-declaration]
  3. Docker Remote API v1.12使用
  4. 牛客网 【每日一题】5月12日题目精讲 模拟战役
  5. 【Linux系统编程学习】 动态库的制作与使用
  6. JS学习笔记(二)变量、作用域及内存问题
  7. Spring的核心思想,这篇文章短小精悍的总结透了
  8. dell linux raid 查看,Ubuntu Linux下Dell服务器使用硬Raid后查看磁盘信息方法
  9. EndNote X8使用总结
  10. 在Excel中批量生成送货单,按数据类别批量生成产品标签
  11. python 微博_用python发微博
  12. 自由职业者:提高效率的6个简单方法
  13. eclipse 工作空间的高效使用
  14. netty源码分析7-NioEventLoop-run方法疑难点
  15. ASUS AC1900p 梅林固件编译 asuswrt-merlin
  16. 了解Intel IPP
  17. 大数据与算法系列之算法性能分析
  18. 小米加密兔正式内测上线,网易星球莱茨狗又多了新对手
  19. opecv BGR转NV21
  20. ES历史索引清理:脚本手动

热门文章

  1. python开发小型数据库_Python开发【第十七篇】:MySQL(一)
  2. DAVY的神龙帕夫——读者的心灵故事|十二橄榄枝的传说
  3. ActiveMq Windows 配置优化
  4. Python中执行外部命令
  5. DAL层修改sql表数据
  6. Velocity.js中文文档
  7. MFC的框架程序分析3
  8. c#中使用消息循环机制发送接收字符串的方法和数据类型转换
  9. python大神作品_Python大神成长之路: 第一次学习记录
  10. 查询排序_MySQL使用UNION连接两个查询排序失效