题目

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(显示出来的字符串),判断键盘坏掉的键

解题思路

  1. 定义int asc[256],记录s2中字符出现的次数
  2. 定义int bk[256],记录坏键是否已打印
  3. 遍历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散列]的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. PAT Advanced 1048 Find Coins (25) [Hash散列]

    题目 Eva loves to collect coins from all over the universe, including some other planets like Mars. On ...

  5. PAT Basic 1047 编程团体赛(20) [Hash散列]

    题目 编程团体赛的规则为:每个参赛队由若⼲队员组成:所有队员独⽴⽐赛:参赛队的成绩为所有队员的成绩和:成绩最⾼的队获胜.现给定所有队员的⽐赛成绩,请你编写程序找出冠军队. 输⼊格式: 输⼊第⼀⾏给出⼀ ...

  6. 1084. Broken Keyboard (20)【字符串操作】——PAT (Advanced Level) Practise

    题目信息 1084. Broken Keyboard (20) 时间限制200 ms 内存限制65536 kB 代码长度限制16000 B On a broken keyboard, some of ...

  7. 1084. Broken Keyboard (20)

    On a broken keyboard, some of the keys are worn out. So when you type some sentences, the characters ...

  8. PAT (Advanced Level) 1084. Broken Keyboard (20)

    简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...

  9. 【PAT甲级】1084 Broken Keyboard (20 分)

    题意: 输入两行字符串,输出第一行有而第二行没有的字符(对大小写不敏感且全部以大写输出). AAAAAccepted code: #define HAVE_STRUCT_TIMESPEC #inclu ...

随机推荐

  1. 记录一次SQLServer 2019 MDS问题的排查

    问题表象: MDS网页里看不到任何建立的模型和实体. 用Excel add in连接,提示SQLServer授权过期. 但实际上SQLServer是企业版,目前并没有过期. 背景分析: 我们的环境是从 ...

  2. 实验吧-隐写术-九连环(steghide)

    下载图片: 拿到kali里binwalk发现有压缩文件,然后foremost分解出来,将分出的压缩文件打开,发现已经被加密. 到这里就有几个思路了:1)暴力破解 2)伪加密 3)继续从图片中寻找信息 ...

  3. 【剑指Offer】面试题03. 数组中重复的数字

    题目 找出数组中重复的数字. 在一个长度为 n 的数组 nums 里的所有数字都在 0-n-1 的范围内.数组中某些数字是重复的,但不知道有几个数字重复了,也不知道每个数字重复了几次.请找出数组中任意 ...

  4. VM安装CentOS7步骤

    VM15下载,在360软件管家就可以下载 CentOS7下载地址:http://mirror.bit.edu.cn/centos/7.6.1810/isos/x86_64/CentOS-7-x86_6 ...

  5. LARGE_INTEGER 64位的输出格式

    %016I64x 第一个016是指当最左边无数据时用00填充:后面的I64x是__int64的前缀要求格式十六进制输出.

  6. Stuts2与SpringMVC

    Struts2:一个基于MVC设计模式的Web应用框架,本质上相当于一个servlet.以WebWork为核心,采用拦截器的机制处理用户的请求(Filter). 轻量级的MVC框架.低侵入性,与业务代 ...

  7. location - 修改url后 - 重新加载

    window.location.href = window.location.pathname + search;

  8. 【LeetCode】最长回文子串-中心扩展法

    [问题]给定一个字符串 s,找到 s 中最长的回文子串.你可以假设 s 的最大长度为 1000. 示例 : 输入: "babad" 输出: "bab" 注意: ...

  9. LICEcap--一款录屏生成Gif的软件

    下载地址:http://www.cockos.com/licecap/ 效果图:

  10. Linux基础(1) 安装

    Linux基础 一.创建CentOS 7 Linux虚拟机 1.安装虚拟机     桥接网络:相当于这台机器就是物理机,多个电脑在连接在一个交换机上,同一个子网 NAT:这台机器只能通过物理机(相当于 ...