PAT (Basic Level) Practice 1029.旧键盘

1029.旧键盘

题目链接-1019.旧键盘
在这里插入图片描述
解题思路

  • 输入a,b两个字符串,只要在b字符串中找不到a字符串中的某个字符,该键即为坏键,用字符串c存一下坏键即可
  • 因为每个坏键只输出一次,也就是说字符串c中不存在相同的字符
  • 在判断某个字符是否存在某个字符串中的时候可以用到string.find()函数

string.find()函数

  • string.find()返回值是字符或字符串在第一次在母串(string)中出现的位置(下标),如果没有找到,那么会返回string::npos
  • 用法: string.find(value),value既可以是一个字符也可以是一个字符串

附上代码

#include<bits/stdc++.h>
#define int long long
#define lowbit(x) (x &(-x))
using namespace std;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
const double eps=1e-10;
const int M=1e9+7;
const int N=1e5+5;
typedef long long ll;
typedef pair<int,int> PII;
string a,b,c;
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	
	cin>>a>>b;
	for(int i=0;i<=a.length();i++){
		if(b.find(a[i])==string::npos&&c.find(toupper(a[i]))==string::npos)
			c+=toupper(a[i]);
	}
	cout<<c<<endl;
	return 0;
}


发布了88 篇原创文章 · 获赞 9 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/Fiveneves/article/details/104545439