PAT乙级1033 旧键盘打字 (20 分)(测试点2)

https://pintia.cn/problem-sets/994805260223102976/problems/994805288530460672

测试点2考察没有坏键的情况,即第一行输入为空
所以不要用cin,用getline

#include 
using namespace std;
int main(){
	string s1, s2, tmp;
	getline(cin, s1);
	getline(cin, s2);
	int s[1000] = {0}, flag = 0;
	for(int i = 0; i < s1.size(); i++){
		if(s1[i] == '+')
			flag = 1;
		else if(s1[i] <= 'Z' && s1[i] >= 'A')
			s[s1[i]-'A'+'a']++;
		s[s1[i]]++;
	}
	for(int i = 0; i < s2.size(); i++){
		if(flag && (s2[i] < 'A' || s2[i] > 'Z') && !s[s2[i]])
			cout << s2[i];
		else if(!flag && !s[s2[i]])
			cout << s2[i];
	}
	return 0;
}

你可能感兴趣的:(PAT乙级)