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

思路
1.set模拟一个字典dic存放键位,队列q按照键位的第一次输入依次存放键,然后根据实际的输入效果确定损坏的键位。
2.当队列不为空时,依次取出队列的首元素,检查是否在字典中已遍历,没遍历表示缺失,直接打印。
10.03:map会自动根据键值排序,所以用队列先记录下键位的输入顺序。。。另外这道题20分ac了19分,一个特殊用例死活过不去,暂且先放着。
11.30:改用set存放值就AC了。
未AC代码
#include<iostream>
#include<map>
#include<queue>
using namespace std;
int main()
{
string s;
string r;
queue<char> q;
map<char,int> dic;
while(cin >> s >> r)
{
for(int i = ;i < s.size();i++)
{
if(s[i] == '_' || dic.count(toupper(s[i])) > )
continue;
else
{
dic.insert(pair<char,int>(toupper(s[i]),));
q.push(toupper(s[i]));
}
} for(int i = ;i < r.size();i++)
{
if(r[i] == '_')
continue;
else
{
dic[toupper(r[i])] = -;
}
} while(!q.empty())
{
if(dic[q.front()] > )
cout << q.front();
q.pop();
}
cout << endl;
}
}

AC代码

#include<iostream>
#include<set>
#include<queue>
using namespace std;
int main()
{
string s;
string r;
queue<char> q;
set<char> dic;
while(cin >> s >> r)
{
for(int i = 0;i < s.size();i++)
{
if(dic.find(toupper(s[i])) == dic.end())
{
dic.insert(toupper(s[i]));
q.push(toupper(s[i]));
}
} for(int i = 0;i < r.size();i++)
{
if(dic.find(toupper(r[i])) != dic.end())
{
dic.erase(toupper(r[i]));
}
} while(!q.empty())
{
if(dic.find(q.front()) != dic.end())
cout << q.front();
q.pop();
}
}
}

  

 

PAT1084:Broken Keyboard的更多相关文章

  1. pat1084. Broken Keyboard (20)

    1084. Broken Keyboard (20) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue On a ...

  2. UVa 11998 Broken Keyboard (数组模拟链表问题)

    题目链接: 传送门 Broken Keyboard #include<bits/stdc++.h> using namespace std; char str[100010]; int m ...

  3. UVa 11988 Broken Keyboard(链表->数组实现)

    /*数组形式描述链表:链表不一定要用指针. 题目链接:UVa 11988 Broken Keyboard 题目大意: 小明没有开屏幕输入一个字符串,电脑键盘出现了问题会不定时的录入 home end ...

  4. 1084. Broken Keyboard (20)

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

  5. B - Broken Keyboard (a.k.a. Beiju Text)

    Problem B Broken Keyboard (a.k.a. Beiju Text) You're typing a long text with a broken keyboard. Well ...

  6. uva - Broken Keyboard (a.k.a. Beiju Text)(链表)

    11988 - Broken Keyboard (a.k.a. Beiju Text) You’re typing a long text with a broken keyboard. Well i ...

  7. PAT 1084 Broken Keyboard

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

  8. A1084. Broken Keyboard

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

  9. B - Broken Keyboard (a.k.a. Beiju Text) 数组模拟链表

    You're typing a long text with a broken keyboard. Well it's not so badly broken. The only problem wi ...

随机推荐

  1. Java实现附近地点搜索

    Java,Mysql-根据一个给定经纬度的点,进行附近500米地点查询–合理利用算法 最近做一个项目:需要查询一个站点(已知该站点经纬度)1km-10km范围内的其它站点.所以,我首先想到的是,对每条 ...

  2. Leetcode_80_Remove Duplicates from Sorted Array II

    本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/43835055 Follow up for "Re ...

  3. 俺的新书《Sencha Touch实战》终于出版了

    内容简介:Sencha框架是第一个基于HTML 5的移动也能给予框架,可以让Web应用看起来像网络应用.美丽的用户 界面 组件和丰富的数据管理,全部基于最新的HTML 5和CSS 3的Web标准,全部 ...

  4. ZooKeeper leader election

    Paxos是分布式应用中解决同步问题的核心.作为应用研发工程师,我们总是倾向于使用一种相对简洁的方式实现复杂的算法.ZooKeeper leader election实现就是一个非常好的参考. 其实现 ...

  5. Struct和Union在内存大小上的区别

    名字起的不好,但是也不知道该叫什么好,题目如下: typedef union {];char c;} DATE; struct data { int i; DATE k; double j; }; i ...

  6. LeetCode(24)-Balanced Binary Tree

    题目: Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced bin ...

  7. MySQL性能调优——索引详解与索引的优化

    --索引优化,可以说是数据库相关优化.理解尤其是查询优化中最常用的优化手段之一.所以,只有深入索引的实现原理.存储方式.不同索引间区别,才能设计或使用最优的索引,最大幅度的提升查询效率! 一.BTre ...

  8. 经典的java中return和finally问题!

    经典的java中return和finally问题! 标签: 杂谈 分类: java学习 前一段时间 参加公司的笔试问了这个问题,回来一查才知道当时自己做错了,百思不得其解,上网查到下面的程序,但是运行 ...

  9. Day20 Django的使用_基础

    老师网址: https://www.cnblogs.com/yuanchenqi/articles/7652353.html 1,复习上级课,一对一,一对多,多对多的使用 models.py: cla ...

  10. 做双网卡绑定_______物理机在双网卡的情况下做多IP绑定

    公司的环境是这样的: 一台物理机需要做双网卡绑定,同时呢,在双网卡绑定的同时还要做多IP. 其实整个过程可以分为两个步骤: 第一个,物理机先做双网卡. 第二个,在bond上做多IP实例. 双网卡绑定的 ...