PAT甲级1084
2017-01-18 22:36
429 查看
1084. Broken Keyboard (20)
时间限制200 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue
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_es
Sample Output:
7TI
#include<cstdio> #include<iostream> #include<string.h> #include<string> #include<vector> #include<algorithm> using namespace std; int main() { bool hashtable[128] = {false}; string s1, s2; cin >> s1 >> s2; int i, j; i = j = 0; while (i < s1.size() && j < s2.size()) { if (s1[i] >= 'a'&&s1[i] <= 'z')s1[i] -= 32; if (s2[j] >= 'a'&&s2[j] <= 'z')s2[j] -= 32; if (s1[i] != s2[j]) { if (!hashtable[s1[i]]) { cout << s1[i]; hashtable[s1[i]] = true; } i++; } else { i++; j++; } } for (int k = i; k < s1.size(); k++) { if (s1[k] >= 'a'&&s1[k] <= 'z')s1[k] -= 32; if(!hashtable[s1[k]]) { cout << s1[k]; hashtable[s1[k]] = true; } } return 0; } /*把小写全转化为大写,然后用hashtable控制输出*/
相关文章推荐
- 使用C++实现JNI接口需要注意的事项
- 关于指针的一些事情
- c++ primer 第五版 笔记前言
- share_ptr的几个注意点
- Lua中调用C++函数示例
- Lua教程(一):在C++中嵌入Lua脚本
- Lua教程(二):C++和Lua相互传递数据示例
- C++联合体转换成C#结构的实现方法
- C++高级程序员成长之路
- C++编写简单的打靶游戏
- C++ 自定义控件的移植问题
- C++变位词问题分析
- C/C++数据对齐详细解析
- C++基于栈实现铁轨问题
- C++中引用的使用总结
- 使用Lua来扩展C++程序的方法
- C++中调用Lua函数实例
- Lua和C++的通信流程代码实例
- C++的template模板中class与typename关键字的区别分析
- C与C++之间相互调用实例方法讲解