【PAT】Type on old keyboard

1033. Typing on an old keyboard (20)

time limit
200 ms
memory limit
65536 kB
code length limit
8000 B
Judgment procedure
Standard
author
CHEN, Yue

Several keys were broken on the old keyboard, so when typing a piece of text, the corresponding character would not appear. Now given a piece of text that should be entered, and the broken keys, what will the resulting text be?

Input format:

Enter the broken keys and the text that should be entered in 2 lines. The bad keys corresponding to English letters are given in uppercase; each text is a string of no more than 10 5 characters. Available characters include letters [az, AZ], numbers 0-9, and underscore "_" (for space), ",", ".", "-", "+" (for shift key). The title ensures that the text string entered on line 2 is not empty.

Note: If the shift key is broken, uppercase English letters cannot be typed.

Output format:

Output the resulting text that can be typed on one line. If none of the characters can be typed, a blank line is output.

Input sample:
7+IE.
7_This_is_a_test.
Sample output:
_hs_s_a_tst

Test point 2 cin>>x>>str is changed to getline, because if x is empty, it will also be processed

#include <iostream>
#include <string>
using namespace std;
int main(){
	int bad[128] = {0};
	string x,str;
	
	getline (cin, x);
	getline (cin, str);
	
	
	
	for(int i = 0; i < x.length(); i++){
		bad[x[i]] = 1;
		bad[tolower(x[i])] = 1;
	}
	if(bad['+'] == 1){
		for(int i = 'A'; i <= 'Z'; i++){
			bad[i] = 1;
		}
	}
	
	for(int i = 0; i < str.length(); i++){
		if(bad[str[i]] != 1){
			cout<<str[i];
		}
	}
	
	return 0;
}

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326886495&siteId=291194637