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

7_This_is_a_test
_hs_s_a_es

Sample Output

7TI

解答

#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;
		}			
	}
	printf("\n");

	return 0;		
}
上一篇: 下一篇:

我的博客

NoAlGo头像编程这件小事牵扯到太多的知识,很容易知其然而不知其所以然,但真正了不起的程序员对自己程序的每一个字节都了如指掌,要立足基础理论,努力提升自我的专业修养。

站内搜索

最新评论