浙江财经大学
信息管理与工程学院

PAT(A) 1084. Broken Keyboard (20)

本文由 Ocrosoft 于 2016-12-28 21:27:26 发表

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 <set>
#include <map>
#include <list>
#include <cmath>
#include <stack>
#include <queue>
#include <ctime>
#include <string>
#include <cstdio>
#include <vector>
#include <cctype>
#include <climits>
#include <sstream>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <functional>
#define strend string::npos
#define ms(a) memset(a,0,sizeof(a))
#define  rep(a,v,b) for(int a=v;a<b;a++)
#define  repe(a,v,b) for(int a=v;a<=b;a++)
typedef long long LL;
const LL LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const int MAXN = 300000+ 10;
const int MOD = 1000000009;
int gcd(int a, int b)
{
	if (!b)return a;
	return gcd(b, a%b);
}
/*(◕‿‿◕)(◕‿‿◕) (◕‿‿◕) (◕‿‿◕) (◕‿‿◕) (◕‿‿◕)*/
/*(◕‿‿◕) 签订契约,成为马猴烧酒吧 (◕‿‿◕)*/
/*(◕‿‿◕)(◕‿‿◕) (◕‿‿◕) (◕‿‿◕) (◕‿‿◕) (◕‿‿◕)*/
using namespace std;
int main()
{
	int vis[60] = { 0 };
	string s, ss;
	cin >> s >> ss;
	for (int i = 0,j=0; i < s.size(); i++)
	{
		if (s[i] != ss[j])
		{
			if (s[i] == '_')
			{
				if(vis[29] == 0)
					printf("_"), vis[29] = 1;
			}
			else if (isdigit(s[i]))
			{
				if (vis[30 + s[i] - '0'] == 0)
					printf("%c", s[i]), vis[30 + s[i] - '0'] = 1;
			}
			else 
			{ 
				if (vis[tolower(s[i]) - 'a'] == 0)
					printf("%c", toupper(s[i])), vis[tolower(s[i]) - 'a'] = 1; 
			}
		}
		else j++;
	}
	cout << endl;
	return 0;
}

欢迎分享与转载,请保留链接与出处。Ocrosoft » PAT(A) 1084. Broken Keyboard (20)

点赞 (0)or拍砖 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址