PAT 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.
输入描写叙述:
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.
输出描写叙述:
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.
输入样例:
7_This_is_a_test_hs_s_a_es
输出样例:
7TI
#include<iostream>
#include <cstring>
#include <cstdlib>
#include <string>using namespace std;const int MAX=80;//去掉字符串中反复的字符
void Remove(char* s, int num)
{int i,j,l;i=j=0;for(i=0;i<num;i++){for(l=0;l<j;l++){if(s[l]==s[i])break;}if(l>=j){s[j++]=s[i];}}s[j]='\0';
}//找出第1个字符串中,没有在第2个字符串中出现的字符。
void Worn(char* lhs, char* rhs, char* result)
{int i,j,k;k=0;for(i=0;lhs[i]!='\0';i++){for(j=0;rhs[j]!='\0';j++){if(lhs[i]==rhs[j])break;}if(rhs[j]=='\0'){result[k++]=lhs[i];}}result[k]='\0';
}int main()
{int i;string n,m;char sn[MAX],sm[MAX],sr[MAX];while(cin>>n>>m){//将输入的字符串1中的小写英文字符转换为大写英文字符for(i=0;i<n.length();i++){sn[i]=n[i];if((sn[i]>=65)&&(sn[i]<=90) || (sn[i]>=97)&&(sn[i]<=122))sn[i]=::toupper(sn[i]);}sn[i]='\0';//将输入的字符串2中的小写英文字符转换为大写英文字符for(i=0;i<m.length();i++){sm[i]=m[i];if((sm[i]>=65)&&(sm[i]<=90) || (sm[i]>=97)&&(sm[i]<=122))sm[i]=::toupper(sm[i]);}sm[i]='\0';/*for(i=0;sn[i]!='\0';i++)cout<<sn[i]<<" ";cout<<endl;for(i=0;sm[i]!='\0';i++)cout<<sm[i]<<" ";cout<<endl;
*/Remove(sn,n.length());Remove(sm,m.length());Worn(sn,sm,sr);for(i=0;sr[i]!='\0';i++)cout<<sr[i];cout<<endl;}return 0;
}
PAT Broken Keyboard (20)相关推荐
- 【简便解法】1084 Broken Keyboard (20 分)_16行代码AC
立志用最少的代码做最高效的表达 PAT甲级最优题解-->传送门 On a broken keyboard, some of the keys are worn out. So when you ...
- 1084. Broken Keyboard (20)
题目例如以下: On a broken keyboard, some of the keys are worn out. So when you type some sentences, the ch ...
- 【PAT甲级 删除字符串中重复字母】1084 Broken Keyboard (20 分) Java 全部AC
题目 题解 Java import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamRead ...
- PAT甲级1084 Broken Keyboard:[C++题解]字符串处理、双指针算法
文章目录 题目分析 题目来源 题目分析 来源:acwing ac代码1:双指针算法 读入两个字符串a和b,用两个指针i和j分别遍历a.b.如果a[i] ==b[j],说明键盘没坏,j往后移动一个:如果 ...
- UVa11988-破损的键盘 Broken Keyboard
题目描述 You're typing a long text with a broken keyboard. Well it's not so badly broken. The only probl ...
- 1112. Stucked Keyboard (20)
1112. Stucked Keyboard (20) 注:如果存在这样的字符串,sss_sssaedsss_s,那么我们认为s是好键(次数为3),所以,在一开始,我们第一次访问的时候,不能马上确定哪 ...
- 例题6-4 破损的键盘(又名:悲剧文本)(Broken Keyboard(a.k.a. Beiju Text), UVa 11988)
例题6-4 破损的键盘(又名:悲剧文本)(Broken Keyboard(a.k.a. Beiju Text), UVa 11988) 链表的应用 #include<iostream> # ...
- Broken Keyboard (a.k.a. Beiju Text)
原题及翻译 Broken Keyboard (a.k.a. Beiju Text) 破碎的键盘(a.k.a. Beiju Text) You're typing a long text with a ...
- 【刘汝佳代码详解】例题6-4破损的键盘(Broken Keyboard,UVa 11988)
立志用最少的代码做最高效的表达 You're typing a long text with a broken keyboard. Well it's not so badly broken. The ...
最新文章
- Django REST framework API 指南(12):验证器
- 全民IT时代到来了?学计算机很有前途?——淘宝2011校园招聘笔试感想
- .NET开发微信小程序-微信支付
- 【多网段切换导致DNS域名解析失败问题处理】
- python正则表达式在线_python正则表达式
- emc文件存储服务器,emc存储怎么挂在linux服务器上
- iNeuOS工业互联网操作系统,智慧用电测控应用案例
- 孙叫兽进阶之路之压力与绩效
- 高级php进修,PHP进修笔记一:PHP的数据类型与常量应用
- 实验五 数据结构综合应用 20162305
- 类似抖音的短视频app开发难度大吗?短视频源码让你事半功倍
- 【Spark】Spark是什么
- 软考 信息安全工程师怎么样
- Hybird App 应用开发中5个必备知识点复习
- 微信小程序使用组件库
- 【Unity3D日常开发】应粉丝邀约,写一篇单例模式在Unity的实际应用,记得一键三连哦
- 互联网创业如何起步(二)
- 软件项目外包平台 公司刚刚创业,人手不够怎么办 外包吧
- 假期错过的...条AI新闻都在这里了
- Centos7用户相关及多用户迁移