PAT_A1084#Broken Keyboard

Posted blue-lin

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PAT_A1084#Broken Keyboard相关的知识,希望对你有一定的参考价值。

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的主要内容,如果未能解决你的问题,请参考以下文章

Pat1084:Broken Keyboard

pat 1084 Broken Keyboard(20 分)

1084 Broken Keyboard (20)

1084. Broken Keyboard (20)

1084. Broken Keyboard (20)

PAT甲级——A1084 Broken Keyboard