题目

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. 三十六、SAP的调试模式

    一.在执行界面,输入/h, 左下角会提示调试模式被激活 二.点击运行,就会跳出调试界面 三.调试界面用法

  2. 112-PHP类变量之间的赋值标识为同一个对象(二)

    <?php class mao{ //定义猫类 public $age=0; //定义多个属性并初始化 public $weight=50; public $color='white'; } $ ...

  3. java枚举类(转)

    转自: http://blog.sina.com.cn/s/blog_697b968901013ih1.html 这里主要讲解的是Java的枚举类型 什么是枚举? 以我的理解答:枚举是我们自己定义的一 ...

  4. 吴裕雄 Bootstrap 前端框架开发——Bootstrap 字体图标(Glyphicons):glyphicon glyphicon-text-width

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name ...

  5. Java高级特性——注解,这也许是最简单易懂的文章了

    最近,浪尖在做flink的项目时source和sink的绑定那块用到了注解,当然新版本1.6以后就变为server load的方式加载. 但是浪尖也是觉得很有毕业讲一下注解,毕竟高级免试也会问答的吧. ...

  6. Selenium2Library:Get Matching Xpath Count用法

    Name:Get Matching Xpath CountSource:Selenium2Library <test library>Arguments:[ xpath ]Returns ...

  7. 【LeetCode】 240. 搜索二维矩阵 II

    题目 编写一个高效的算法来搜索 m x n 矩阵 matrix 中的一个目标值 target.该矩阵具有以下特性: 每行的元素从左到右升序排列. 每列的元素从上到下升序排列. 示例: 现有矩阵 mat ...

  8. LightOJ - 1282 Leading and Trailing (数论)

    题意:求nk的前三位和后三位. 分析: 1.后三位快速幂取模,注意不足三位补前导零. 补前导零:假如nk为1234005,快速幂取模后,得到的数是5,因此输出要补前导零. 2.前三位: 令n=10a, ...

  9. POJ 2239:Selecting Courses 选课

    Selecting Courses Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9380   Accepted: 4177 ...

  10. POJ 1185:炮兵阵地

    炮兵阵地 Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 21366   Accepted: 8280 Description ...