Pat 甲级 训练真题集 1084!

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.

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

仅仅为字符串处理,我利用了find_first_not_of与erase函数

代码如下:

#include<iostream>
#include<string>
using namespace std;
int main(){
	string s1,s2,s3="";
	cin>>s1>>s2;
	int index=0;
	while(index!=-1){
		int index1=-1;
		index=s1.find_first_not_of(s2);
		if(index!=-1){
			char a=toupper(s1[index]);	
			index1=s3.find(a);
			if(index1==-1){
				s3+=a;
			}
			s1.erase(index,1);	
		}
	}
	cout<<s3;
	return 0;
}

下面文章的代码未简化

1059. Prime Factors (25)-PAT甲级真题(素数表的建立)

打赏一个呗

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦