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[比较]的更多相关文章

  1. PAT 1084 Broken Keyboard

    1084 Broken Keyboard (20 分)   On a broken keyboard, some of the keys are worn out. So when you type ...

  2. 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 ...

  3. 1084. Broken Keyboard (20)【字符串操作】——PAT (Advanced Level) Practise

    题目信息 1084. Broken Keyboard (20) 时间限制200 ms 内存限制65536 kB 代码长度限制16000 B On a broken keyboard, some of ...

  4. 1084 Broken Keyboard (20 分)

    1084 Broken Keyboard (20 分) On a broken keyboard, some of the keys are worn out. So when you type so ...

  5. 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 ...

  6. 1084. Broken Keyboard (20)

    On a broken keyboard, some of the keys are worn out. So when you type some sentences, the characters ...

  7. PAT (Advanced Level) 1084. Broken Keyboard (20)

    简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...

  8. 【PAT甲级】1084 Broken Keyboard (20 分)

    题意: 输入两行字符串,输出第一行有而第二行没有的字符(对大小写不敏感且全部以大写输出). AAAAAccepted code: #define HAVE_STRUCT_TIMESPEC #inclu ...

  9. 1084. Broken Keyboard (20)-水题

    #include <iostream> #include <cstdio> #include <string.h> #include <algorithm&g ...

随机推荐

  1. 2015 Multi-University Training Contest 3 1002 RGCDQ

    RGCDQ Problem's Link: http://acm.hdu.edu.cn/showproblem.php?pid=5317 Mean: 定义函数f(x)表示:x的不同素因子个数. 如:f ...

  2. 判断gridView是否有数据

    我这里的gridView是采用空模板数据来显示的 当gridView的数据源为空的时候它们就会显示标题 有数据的显示它们就会显示下面的这种 你仔细观察会发现,当有数据的时候空标题的table没有了,解 ...

  3. sql 更新字段

    UPDATE YpeopleSET power='0'WHERE power='1'; UPDATE Ypeople SET power='1' WHERE power='0' and pid='22 ...

  4. dedecms中如何去掉文章页面的广告

    在arcticle_arcticle.htm页面找到广告调用代码{dede:myad name='myad'/}全部去掉就好了,如果要换成自己的广告,就换广告位标识 myad 就可以了

  5. Python之查询美国护照状态

    该程序会每隔至少1秒进行一次护照状态查询 需要修改passportNo变量为自己的护照号码. 另外需要pip install beautifulsoup4 #coding=utf-8 import r ...

  6. C++继承具体解释之二——派生类成员函数具体解释(函数隐藏、构造函数与兼容覆盖规则)

    在这一篇文章開始之前.我先解决一个问题. 在上一篇C++继承详解之中的一个--初探继承中,我提到了在派生类中能够定义一个与基类成员函数同名的函数,这样派生类中的函数就会覆盖掉基类的成员函数. 在谭浩强 ...

  7. querySelectorAll 和getElementsByClassName的区别

    querySelectorAll 返回的是映射 改变其值不会改变document 而getElementsByClassName 改变它就会改变document 摘自JavaScript权威指南(jQ ...

  8. 漫游kafka实战篇之搭建Kafka开发环境(3)

    上篇文章中我们搭建了kafka的服务器,并可以使用Kafka的命令行工具创建topic,发送和接收消息.下面我们来搭建kafka的开发环境.   添加依赖   搭建开发环境需要引入kafka的jar包 ...

  9. JBPM4.4_工作流基础_准备jBPM4.4环境

    1. 工作流基础 1.1. 工作流相关概念 工作流(Workflow),就是“业务过程的部分或整体在计算机应用环境下的自动化”,它主要解决的是“使在多个参与者之间按照某种预定义的规则传递文档.信息或任 ...

  10. 【BZOJ3790】神奇项链 Manacher+贪心

    [BZOJ3790]神奇项链 Description 母亲节就要到了,小 H 准备送给她一个特殊的项链.这个项链可以看作一个用小写字 母组成的字符串,每个小写字母表示一种颜色.为了制作这个项链,小 H ...