PAT 1084 Broken Keyboard[比较]
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_es
Sample Output:
7TI
题目大意:有一些键盘字母坏了,打不出来,现在给出原输入和显示的字符串,判断哪些按键坏掉了,并且按发现顺序输出。
//第一次提交的发现最后一个点过不去,去牛客网上提交发现以下问题:

主要是没有考虑到,如果s2已经比对完了,但是s1中还剩下很多没有比对,那么剩下的那些自动就是键盘坏掉的。再判断一下就可以啦。
#include <iostream>
#include <algorithm>
#include<cstdio>
#include<stdio.h>
#include <queue>
#include<cmath>
#include <vector>
#include<set>
using namespace std; int main()
{
string s1,s2;
set<char> st;
vector<char> vt;
cin>>s1>>s2;
int i=;
while(i<s1.size()&&i<s2.size()){
if(s1[i]!=s2[i]){
if(isalpha(s1[i])){
s1[i]=toupper(s1[i]);
}
if(st.count(s1[i])==){
st.insert(s1[i]);
vt.push_back(s1[i]);
}
//s1.substr(i,1);这样写不正确,s1并不会有实质性的变化。。
//s1=s1.substr(i,1);这样也不对,你要知道你要留下哪部分。。
s1=s1.erase(i,);
}else i++;
}
if(i<s1.size()){
for(int j=i;j<s1.size();j++){
if(isalpha(s1[j])){
s1[j]=toupper(s1[j]);
}
if(st.count(s1[j])==){
st.insert(s1[j]);
vt.push_back(s1[j]);
}
}
}
// for(int j=0;j<st.size();j++){
// cout<<st[i];
// }
for(int j=;j<st.size();j++){
cout<<vt[j];
}
return ;
}
1.在set中查找是否相同使用count函数。
//我的天,看了柳神的解答之后,我被颠覆了。

//毕竟是柳神
1.使用string的find函数,对于s1中的每一个,如果没在s2中出现,并且没有在ans中出现,那么就是键盘坏了。
PAT 1084 Broken Keyboard[比较]的更多相关文章
- PAT 1084 Broken Keyboard
1084 Broken Keyboard (20 分) On a broken keyboard, some of the keys are worn out. So when you type ...
- pat 1084 Broken Keyboard(20 分)
1084 Broken Keyboard(20 分) On a broken keyboard, some of the keys are worn out. So when you type som ...
- 1084. Broken Keyboard (20)【字符串操作】——PAT (Advanced Level) Practise
题目信息 1084. Broken Keyboard (20) 时间限制200 ms 内存限制65536 kB 代码长度限制16000 B On a broken keyboard, some of ...
- 1084 Broken Keyboard (20 分)
1084 Broken Keyboard (20 分) On a broken keyboard, some of the keys are worn out. So when you type so ...
- PAT Advanced 1084 Broken Keyboard (20) [Hash散列]
题目 On a broken keyboard, some of the keys are worn out. So when you type some sentences, the charact ...
- 1084. Broken Keyboard (20)
On a broken keyboard, some of the keys are worn out. So when you type some sentences, the characters ...
- PAT (Advanced Level) 1084. Broken Keyboard (20)
简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...
- 【PAT甲级】1084 Broken Keyboard (20 分)
题意: 输入两行字符串,输出第一行有而第二行没有的字符(对大小写不敏感且全部以大写输出). AAAAAccepted code: #define HAVE_STRUCT_TIMESPEC #inclu ...
- 1084. Broken Keyboard (20)-水题
#include <iostream> #include <cstdio> #include <string.h> #include <algorithm&g ...
随机推荐
- 在linux 列出 超级用户 普通用户和 系统用户
#!/bin/bash echo Please select which list you want to print echo "1. admin (enter 1)" echo ...
- XML 是一种元语言, 可以用它来描述其他语言。
A.正确 B.错误 解答:B XML(Extensible Markup Language)即可扩展标记语言,它与HTML一样,都是SGML(Standard Generalized Markup L ...
- 百家搜索:在站点中加入Google、百度等搜索引擎
来源:http://www.ido321.com/1143.html 看到一些站点上加入了各种搜索引擎. 如Google.百度.360.有道等.就有点好奇.这个怎么实现?研究了一各个搜索引擎怎么传送k ...
- Yii2发送邮箱总结
修改配置文件,普通版在(config/web.php).高级版默认配置在/common/config/main-local.php 'components' => [ 'mailer' => ...
- Android使用Intent实现拨打电话的动作
使用Intent实现打电话的动作,我们须要在 AnroidMainfest.xml中增加通话权限,打开这个文件,在application节点的前面增加以下内容 <uses-permission ...
- 多线程环境下调用 HttpWebRequest 并发连接限制
.net 的 HttpWebRequest 或者 WebClient 在多线程情况下存在并发连接限制,这个限制在桌面操作系统如 windows xp , windows 7 下默认是2,在服务器操作 ...
- oracle decode处理被除数为0 的情况
,,a) per from aa; 例如 我的b为(N30+N31+N32+N33+N34+N35+N36+N37+N38) ,,(N33)||'%' WHERE ssrq=''||sssq||'';
- 数据库布尔型状态字段互斥性的SQL更新操作
一个配置表或者一个存储了多条状态的表,需要在某个状态中做切换,而当前是否启用状态标记是用0和1来标识的.这个时候通常 1表示正在使用中,0表示不在使用中.通常有些业务会做一些配置的状态切换,就会出现要 ...
- jQuery插件手把手教会(一)
jQuery插件开发教程 ——让你的jQuery水平提升一个台阶 要说jQuery 最成功的地方,我认为是它的可扩展性吸引了众多开发者为其开发插件,从而建立起了一个生态系统.这好比大公司们争相做平台 ...
- golang 之 channel
channel的机制是先进先出 无缓冲的channel: 如果你给channel赋值了,那么必须要读取它的值,不然就会造成阻塞. chreadandwrite :=make(chan int) cho ...