Not Only Algorithm,不仅仅是算法,关注数学、算法、数据结构、程序员笔试面试以及一切涉及计算机编程之美的内容 。。
你的位置:NoAlGo博客 » 题解 » 

PAT 1084. 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


Sample Output



#include <cstdio>
#include <ctype.h>
using namespace std;

bool exist[1000] = {0};
char s1[10000], s2[10000];

int main()
	scanf("%s%s", s1, s2);
	for (char *p1 = s1, *p2 = s2; *p1; p1++)
		char x = toupper(*p1), flag = 0;

		if (!*p2) flag = 1;
		else if (toupper(*p2) == x) p2++;
		else flag = 1;

		if (flag && !exist[x])
			printf("%c", x);
			exist[x] = 1;

	return 0;		
上一篇: 下一篇: