PAT A1084. Broken Keyboard (20)
PAT A1084. Broken Keyboard (20)
阿豪boy 发表于10个月前
PAT A1084. Broken Keyboard (20)
  • 发表于 10个月前
  • 阅读 3
  • 收藏 0
  • 点赞 0
  • 评论 0

https://www.patest.cn/contests/pat-a-practise/1084

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

 

思路:

1,如何在英文字母不区分大小写的情况下判断在第一个字符串中有哪些字符没有在第二个字符串中出现

2,如何保证同一个字符不区分大小写的情况下只输出一次,且均用大写输出

#include <iostream>
#include <cstdio>
#include <string.h>

using namespace std;

char a[111],b[111];
int cmp(char a,char b){
	return toupper(a)==toupper(b);
}
bool flag[200]={0};
int main(int argc, char *argv[])
{
	int lena,lenb;
	scanf("%s %s",a,b);
	lena = strlen(a);
	lenb=strlen(b);	
	for(int i=0;i<lenb;i++){
		for(int j=0;j<lena;j++){
			if(a[j] && cmp(a[j],b[i]) )
				a[j]=0;
		}
	} 
	
	for(int i=0;i<lena;i++)
		if(a[i] && !flag[ toupper(a[i])] ){
			printf("%c",toupper(a[i]));
			flag[ toupper(a[i])]=1;
		}
	printf("\n");
	return 0;
}

 

共有 人打赏支持
粉丝 3
博文 477
码字总数 357742
×
阿豪boy
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: