PAT-乙-1033 1033 旧键盘打字 (20 分)

在这里插入图片描述

代码

#include <iostream>

using namespace std;

int main() {

	int ch[129] = {0};
	
	string s1, s2;
	getline(cin, s1);
	getline(cin, s2);
	
	for(int i=0; i<s1.length(); i++){
		ch[s1.at(i)] = 1;
		if(s1.at(i)>='A' && s1.at(i)<='Z'){
			ch[s1.at(i)+32] = 1;
		}
	}
	if(ch['+']==1){
		for(int i='A'; i<='Z'; i++){
			ch[i] = 1;
		}
	}
	
	for(int i=0; i<s2.length(); i++){
		if(ch[s2.at(i)]==0){
			cout<<s2.at(i);
		}
	}
	cout<<endl;
	
	return 0;
}

注解

1、字符数组的思想(该思想用在排序中,对应的是桶排序)
2、getline的用法(此题如果用cin<<s会有一个case是Wrong Answer!,因此必须用getline一次读入一行!)

结果

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/zhanggirlzhangboy/article/details/82947794
今日推荐