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 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
hssaes
题目分析
输入s1(应该输入的字符串),s2(显示出来的字符串),判断键盘坏掉的键
解题思路
- 定义int asc[256],记录s2中字符出现的次数
- 定义int bk[256],记录坏键是否已打印
- 遍历s1找到在s1中未出现在s2中的字符(asc[s1[i]]==0)
- 若bk[asc[s1[i]]]==0表示未打印过,则打印,并将其值置为1,表示该坏键已打印
- 若bk[asc[s1[i]]]==1表示已打印过,不再打印
Code
#include <iostream>
#include <cstring>
using namespace std;
int main(int argc, char * argv[]) {
char s1[81],s2[81];
cin.getline(s1,81);
cin.getline(s2,81);
int asc[256]= {0},bk[256]= {0};
int len1=strlen(s1),len2=strlen(s2);
for(int i=0; i<len2; i++) {
asc[toupper(s2[i])]++;
}
for(int i=0; i<len1; i++) {
char temp = toupper(s1[i]);
if(asc[temp]==0&&bk[temp]==0){
printf("%c",temp);
bk[temp]=1;
}
}
return 0;
}
PAT Advanced 1084 Broken Keyboard (20) [Hash散列]的更多相关文章
- PAT Advanced 1050 String Subtraction (20) [Hash散列]
题目 Given two strings S1 and S2, S = S1 – S2 is defined to be the remaining string afer taking all th ...
- PAT Advanced 1041 Be Unique (20) [Hash散列]
题目 Being unique is so important to people on Mars that even their lottery is designed in a unique wa ...
- PAT Advanced 1134 Vertex Cover (25) [hash散列]
题目 A vertex cover of a graph is a set of vertices such that each edge of the graph is incident to at ...
- PAT Advanced 1048 Find Coins (25) [Hash散列]
题目 Eva loves to collect coins from all over the universe, including some other planets like Mars. On ...
- PAT Basic 1047 编程团体赛(20) [Hash散列]
题目 编程团体赛的规则为:每个参赛队由若⼲队员组成:所有队员独⽴⽐赛:参赛队的成绩为所有队员的成绩和:成绩最⾼的队获胜.现给定所有队员的⽐赛成绩,请你编写程序找出冠军队. 输⼊格式: 输⼊第⼀⾏给出⼀ ...
- 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)
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 ...
随机推荐
- 三十、SAP中的内置图标
一.选择[编辑]->[模式] 二.选中写入模式 三.选中图标 四.选择我们需要的图标 五.选中图标后,选择复制 六.点击之后,会回到代码界面,如下 七.执行结果如下,显示出了一个神奇的图标
- 085-PHP文件引用include(二)
01.php <?php function foo() { global $color; include '02.php'; echo "A $color $fruit"; ...
- T_SQL 将一列多行数据合并为一行
SQL Server在进行数据迁移和报表处理的时候会遇到将一列多行数据拼接为一个字符串的情况,为了处理这个问题,在网上找了一些相关的资料,提供两种方法,供遇到类似问题的朋友们参考,也借此加深自己的印象 ...
- Python 打开文件(File Open)
版权所有,未经许可,禁止转载 章节 Python 介绍 Python 开发环境搭建 Python 语法 Python 变量 Python 数值类型 Python 类型转换 Python 字符串(Str ...
- Object.keys(),Object.values(),Object.entries()
(1)Object.keys() // 返回数组,成员是参数对象自身的(不含继承的)所有可遍历(enumerable)属性的键名. eg:var obj = {a:1,b:'gy'} Ob ...
- kettle将csv文件导入数据库
具体过程学习了: 1.连接数据库 2.添加新资源库 3.选择Other Repositories 4.选择Database Repository,第二个需要配置额外参数 5.连接数据库相关设置 6.连 ...
- git 公钥 ssh
1 安装 git 2 桌面右击 Git Bash Here 3 命令: git config --global user.name "git账户" git config --gl ...
- JVM探秘:MAT分析内存溢出
本系列笔记主要基于<深入理解Java虚拟机:JVM高级特性与最佳实践 第2版>,是这本书的读书笔记. MAT是分析Java堆内存的一个工具,全称是 The Eclipse Memory A ...
- 201771010123汪慧和《面向对象程序设计Java》第十二周实验总结
一.理论部分 1.在Java提供的GUI构建工具中可以分为组件和容器两类. 2.在Java中的组件有:按钮.标签.复选框.单选按钮.选择框.列表框.文本框.滚动条.画布.菜单. 3.在Java中的容器 ...
- Oracle专题
定时任务:JOB文件夹 监视执行过的SQL 语句 select * from v$sqlarea a where module='PL/SQL Developer' order by a.FIRST_ ...