1084. Broken Keyboard (20)
2015-09-08 22:15
393 查看
题目链接:http://www.patest.cn/contests/pat-a-practise/1084
题目:
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:
Sample Output:
分析:
给出两个字符串,原串和键盘坏后输出显示的字符串,找出坏掉的按键,就是找出两个串包含的字符,做个差集就可以
注意一下大小写字符的处理以及重复的处理
AC代码:
截图:
——Apie陈小旭
题目:
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
分析:
给出两个字符串,原串和键盘坏后输出显示的字符串,找出坏掉的按键,就是找出两个串包含的字符,做个差集就可以
注意一下大小写字符的处理以及重复的处理
AC代码:
#include<stdio.h> #include<iostream> #include<string> #include<vector> #include<algorithm> #include<string.h> using namespace std; int main(){ freopen("F://Temp/input.txt", "r", stdin); string str_in, str_out; cin >> str_in >> str_out; transform(str_in.begin(), str_in.end(), str_in.begin(), ::toupper);//先处理为都是大写的情况 transform(str_out.begin(), str_out.end(), str_out.begin(), ::toupper); string str_in_2, str_out_2; for (int i = 0; i < str_in.size(); ++i){ if (str_in_2.find(str_in[i]) == string::npos){ str_in_2 += str_in[i]; } } for (int i = 0; i < str_out.size(); ++i){ if (str_out_2.find(str_out[i]) == string::npos){ str_out_2 += str_out[i]; } } for (int i = 0; i < str_in_2.size(); ++i){ if (str_out_2.find(str_in_2[i]) == string::npos){//输出中没有输出的这个字符,那么就是坏键盘,输出 cout << str_in_2[i]; } } cout << endl; return 0; }
截图:
——Apie陈小旭
相关文章推荐
- Eclipse+pydev插件-----python开发环境
- 披露车辆智能防盗系统安全隐患的国外论文
- Struts2数据的封装
- 创建java线程方式之三实现Callable接口
- 自定义ViewPagerIndicator(下)
- PHP实现留言本代码
- 某点处的导函数值+c语言
- HDU 4010 动态树LCT学习
- hdu5011Game nim博弈
- UVA-1220 Party at Hali-Bula (树的最大独立集)
- C++ nontrival class 值传递的机制。
- C++ nontrival class 值传递的机制。
- ThinkPad T430i黑苹果Yosemite 10.10.3成功显卡驱动
- WebKit官方又开始发布源代码压缩包了
- 1083. List Grades (25)
- 简单二维数组转置问题
- 线程池原理Java
- .net重启iis线程池和iis站点程序代码分享
- MySQL博文归类
- BOM和DOM