1084. Broken Keyboard (20)
来源:互联网 发布:windows 10可以投屏吗 编辑:程序博客网 时间:2024/06/13 19:30
1084. Broken Keyboard (20)
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_esSample Output:
7TI
解析:本题并没有使用双重循环一遍遍的查找缺失的字母,而是采用效率较高的索引方法,只需要单层循环就可以搞定了,运用了HASH的思想;另外PAT题目本身的测试数据有时会有坑,譬如1 2 3后面可能有10个空格和一个换行,而且这种现象在PAT题目中还很普遍,从程序的角度看这不算是测试数据问题,因为你的程序必须对不可见字符有屏蔽能力,有一定的鲁棒性。解决的办法很简单,只需要2行代码:
while ((ch = getchar()) != '\n') ;
/*************************************************************************> File Name: 1084.c> Author: YueBo> Mail: yuebowhu@163.com> Created Time: Sun 14 May 2017 08:40:44 AM CST ************************************************************************/#include<stdio.h>#include <stdlib.h>#include <string.h>int main(){ int characters[10+26+1]; char input[128]; char ch; int loopi; int len; for (loopi = 0; loopi < 10+26+1; loopi++) characters[loopi] = 0; scanf("%s", input); while ((ch = getchar()) != '\n') ; while ((ch = getchar()) != '\n') { if (ch == '_') characters[10+26] = 1; else if (ch >= '0' && ch <= '9') characters[ch-'0'] = 1; else { if (ch >= 'A' && ch <= 'Z') characters[10+ch-'A'] = 1; else characters[10+ch-'a'] = 1; } } len = strlen(input); for (loopi = 0; loopi < len; loopi++) { if (input[loopi] >= 'a' && input[loopi] <= 'z') input[loopi] -= 32; if (input[loopi] == '_') { if (characters[10+26] == 0) { printf("%c", input[loopi]); characters[10+26] = 1; } } else if (input[loopi] >= '0' && input[loopi] <= '9') { if (characters[input[loopi]-'0'] == 0) { printf("%c", input[loopi]); characters[input[loopi]-'0'] = 1; } } else { if (characters[10+input[loopi]-'A'] == 0) { printf("%c", input[loopi]); characters[10+input[loopi]-'A'] = 1; } } } printf("\n"); return 0;}
0 0
- 1084. Broken Keyboard (20)
- 1084. Broken Keyboard (20)
- 1084. Broken Keyboard (20)
- 1084. Broken Keyboard (20)
- 1084. Broken Keyboard (20)
- 1084. Broken Keyboard (20)
- 1084. Broken Keyboard (20)
- 1084. Broken Keyboard (20)
- 1084. Broken Keyboard (20)
- 1084. Broken Keyboard (20)
- 1084. Broken Keyboard (20)
- 1084. Broken Keyboard (20)
- 1084. Broken Keyboard (20)
- 1084. Broken Keyboard (20)
- 1084. Broken Keyboard (20)
- 1084. Broken Keyboard (20)
- 1084. Broken Keyboard (20)
- 1084. Broken Keyboard (20)
- ruby变量和运算符
- vs2015简单配置opencv3.1
- 如何通过Keras来掌握深度学习
- AE学习笔记(2):关键帧动画与技法
- (个人)AR电子书系统创新实训第一周(1)
- 1084. Broken Keyboard (20)
- OIBH基础版普及组7月月赛 天天去旅行
- OpenCV图像坐标系与行列宽高的关系
- maven中The pom for .........is missing,no depency information available
- Navicat连接oracle报ORA-12514错误
- 多尺度特征融合
- 三种查看文件MD5 SHA*等校验值的方法
- 算法导论 思考题 13-1
- Excel VBA 移动文件和文件夹