PAT1084. Broken Keyboard

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
思路:本题可以借鉴的地方是Harsh一共开了128个单元。 足以涵盖任何字符。  并且此题有一处需要注意,最后的while循环不要省略

 1 #include <iostream>
 2 #include <cstring>
 3 #include <cstdio>
 4 using namespace std;
 5 bool Harsh[128]={false};
 6 void Print(char ch)
 7 {
 8     if(ch>=‘a‘&&ch<=‘z‘)
 9         ch-=32;
10     if(!Harsh[ch])
11     {
12
13         putchar(ch);
14     }
15     Harsh[ch]=true;
16 }
17
18 int main(int argc, char *argv[])
19 {
20     char ori[85];
21     char now[85];
22     scanf("%s %s",ori,now);
23     int i,j;
24     for(i=0,j=0;ori[i]!=‘\0‘&&now[j]!=‘\0‘;)
25     {
26         if(ori[i]!=now[j])
27         {
28             Print(ori[i]);
29             i++;
30         }
31         else
32         {
33             i++;
34             j++;
35         }
36     }
37     while(ori[i]!=‘\0‘)
38        Print(ori[i++]);
39     putchar(‘\n‘);
40
41     return 0;
42 }

时间: 2024-10-15 00:13:19

PAT1084. Broken Keyboard的相关文章

pat1084. Broken Keyboard (20)

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.

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 it’s not so badly broken. The only problemwith the keyboard is that sometimes the “home” key or the “end” key gets automatically pressed(internally).Yo

UVa11988:Broken Keyboard

Description Broken KeyboardYou're typing a long text with a broken keyboard. Well it's not so badly broken. The only problem with the keyboard is that sometimes the "home" key gets automatically pressed (internally). You're not aware of this iss

UVA11988 Broken Keyboard (a.k.a. Beiju Text)【数组模拟链表】

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 with the keyboard is that sometimes the "home" key or the "end" key gets automatically pressed (inter

UVa11988-破损的键盘 Broken Keyboard

题目描述 You're typing a long text with a broken keyboard. Well it's not so badly broken. The only problem with the keyboard is that sometimes the "home" key or the "end" key gets automatically pressed (internally). You're not aware of thi

N - Broken Keyboard (a.k.a. Beiju Text)

N - Broken Keyboard (a.k.a. Beiju Text) Time Limit:1000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Description You’re typing a long text with a broken keyboard. Well it’s not so badly broken. The only problem with the keyboard is that som

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, p

1084. Broken Keyboard (20)【字符串操作】——PAT (Advanced Level) Practise

题目信息 1084. Broken Keyboard (20) 时间限制200 ms 内存限制65536 kB 代码长度限制16000 B 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

A1084. 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, p