PAT1084: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 思路
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的更多相关文章
- pat1084. Broken Keyboard (20)
1084. Broken Keyboard (20) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue On a ...
- UVa 11998 Broken Keyboard (数组模拟链表问题)
题目链接: 传送门 Broken Keyboard #include<bits/stdc++.h> using namespace std; char str[100010]; int m ...
- UVa 11988 Broken Keyboard(链表->数组实现)
/*数组形式描述链表:链表不一定要用指针. 题目链接:UVa 11988 Broken Keyboard 题目大意: 小明没有开屏幕输入一个字符串,电脑键盘出现了问题会不定时的录入 home end ...
- 1084. Broken Keyboard (20)
On a broken keyboard, some of the keys are worn out. So when you type some sentences, the characters ...
- 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 ...
- 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 ...
- PAT 1084 Broken Keyboard
1084 Broken Keyboard (20 分) On a broken keyboard, some of the keys are worn out. So when you type ...
- A1084. Broken Keyboard
On a broken keyboard, some of the keys are worn out. So when you type some sentences, the characters ...
- 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 ...
随机推荐
- MVC学习笔记(一)
首先感谢慕课网这个平台提供给我的学习机会,感谢PengCheng老师的"MVC架构模式分析与设计课程". 1.数组的声明: $controllerAllow = array('te ...
- 主流列式数据库评测:InfiniDB
).本文测试的InfiniDB版本是2010年12月20日发布的2.02版,下载文件名分别为InfiniDB64-2.0.2-2.exe 和InfiniDB64-ent-2.0.2-2.exe.安装文 ...
- 【Android 应用开发】Android UI 设计之 TextView EditText 组件属性方法最详细解析
. 作者 :万境绝尘 转载请注明出处 : http://blog.csdn.net/shulianghan/article/details/18964835 . TextView 相关类的继承结构 ...
- cocos2d-x项目与vs2013编译
cocos2d-x项目与vs2013编译 2014-12-17 cheungmine 因为C++11引入了众多开源软件的特性,导致cocos2d-x r3.3项目无法用 vs2010编译. 所以安装了 ...
- Linux打包命令 - tar
上一篇文章谈到的命令大多仅能针对单一文件来进行压缩,虽然 gzip 与 bzip2 也能够针对目录来进行压缩, 不过,这两个命令对目录的压缩指的是『将目录内的所有文件 "分别" 进 ...
- redis菜鸟教程
Redis 简介 http://www.runoob.com/redis/redis-intro.html Redis 安装 http://www.runoob.com/redis/redis-ins ...
- 数据结构---栈C语言实现
#include <stdio.h> #include <stdlib.h> #define uchar unsigned char #define uint unsigned ...
- obj-c编程10:Foundation库中类的使用(6)[线程和操作队列]
任何语言都不能避而不谈线程这个东东,虽然他是和平台相关的鸟,虽说unix哲学比较讨厌线程的说...线程不是万能灵药,但有些场合还是需要的.谈到线程就不得不考虑同步和死锁问题,见如下代码: #impor ...
- 二叉树(LeetCode) C++相关知识代码 系列1
0.二叉树最大深度 原题目:Given a binary tree, find its minimum depth.The minimum depth is the number of nodes a ...
- 以太坊智能合约虚拟机(EVM)原理与实现
以太坊 EVM原理与实现 以太坊底层通过EVM模块支持合约的执行与调用,调用时根据合约地址获取到代码,生成环境后载入到EVM中运行.通常智能合约的开发流程是用solidlity编写逻辑代码,再通过编译 ...