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 ...
随机推荐
- servlet的基本类和接口
javax.servlet.Servlet接口 javax.servlet.GenericServlet类(协议无关版本) javax.servlet.http.HttpServlet类(HTTP版本 ...
- s曲线
一. 原型 sigmoid 函数原型: 在 [-5, 5] 上的曲线是这个样子的: 二.X轴变形 如果我们希望加速更快一点,那么就需要对原型中的指数 -X 的系数进行改变.原型可以认为是 -(1 * ...
- 修改电脑IP地址和MAC地址
一.修改IP地址: 电脑右下角:上网的图标,点击右键,打开“网络和共享中心”, 点击“本地连接”,打开的窗口点击“属性”, 打开新窗口,找到“IPv4”,点击“属性”, 打开新窗口,修改ip,保存,关 ...
- 中国移动携手华为百度展示5G应用,实现8K视频传输
在今日举行的 2019 年百度云智峰会上,中国移动携手华为和百度,首次展示基于 SA 架构的 5G Vertical LAN (行业局域网)技术,承载 8K 实时会议系统,助力企业云办公.该技术可为合 ...
- POJ 1045:Bode Plot
Bode Plot Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 13392 Accepted: 8462 Descri ...
- 解决CGrIdCtrl合并单元格后继续拆分后的问题
DWORD dwMergeCellCount = vMergeCells.size(); ; i < dwMergeCellCount; i++){ m_HFlexGrid.SplitCells ...
- 关于Promise的异步依次函数调用
在Promise中async用于定义一个异步函数(可不写),该函数返回一个Promise. 如果async函数返回的是一个同步的值,这个值将被包装成一个理解resolve的Promise, 等同于re ...
- CSS - input 美化
input{ padding: 20px; width: 100%; height: 5vh; margin-bottom: 2vh; border-radius: 10vw; border: 0; ...
- mybatis环境搭建(eclipse,idea)
基于java配置SSM,eclipse 新建maven,web项目 .... 项目结构: jar包 pom.xml spring和DispatcherServlet上下文 public class D ...
- C++ STD Gems06
generate.generate_n.sample.iota #include <iostream> #include <vector> #include <strin ...