码迷,mamicode.com
首页 > 其他好文 > 详细

PAT_A1084#Broken Keyboard

时间:2019-07-21 20:06:42      阅读:118      评论:0      收藏:0      [点我收藏+]

标签:put   get   HERE   pre   letter   sed   tee   style   script   

Source:

PAT A1084 Broken Keyboard (20 分)

Description:

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

Keys:

Code:

 1 /*
 2 Data: 2019-07-21 19:31:31
 3 Problem: PAT_A1084#Broken Keyboard
 4 AC: 10:43
 5 
 6 题目大意:
 7 给定输入和输出字符串,打印坏掉的键(大写)
 8 */
 9 
10 #include<cstdio>
11 #include<string>
12 #include<iostream>
13 #include<algorithm>
14 using namespace std;
15 char mp[128]={0};
16 
17 int main()
18 {
19 #ifdef    ONLINE_JUDGE
20 #else
21     freopen("Test.txt", "r", stdin);
22 #endif
23 
24     string s,t,r="";
25     cin >> s >> t;
26     transform(s.begin(),s.end(),s.begin(),::toupper);
27     transform(t.begin(),t.end(),t.begin(),::toupper);
28     for(int i=0; i<s.size(); i++)
29     {
30         if(t.size()!=0 && s[i]==t[0])
31             t.erase(0,1);
32         else
33         {
34             mp[s[i]]++;
35             if(mp[s[i]]==1)
36                 r += s.substr(i,1);
37         }
38     }
39     cout << r;
40 
41     return 0;
42 }

 

PAT_A1084#Broken Keyboard

标签:put   get   HERE   pre   letter   sed   tee   style   script   

原文地址:https://www.cnblogs.com/blue-lin/p/11222423.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!