string的find()函数,即PAT1029总结

1.C++ string中的find()函数

一直都对c++的find函数不太明白,做了此题以后,理解的更透彻了。
最初,我只理解这种形式:

 char stl[] ="http://c.biancheng.net/stl/";
    //调用 find() 查找第一个字符 'c'
    char * p = find(stl, stl + strlen(stl), 'c');
    //判断是否查找成功
    if (p != stl + strlen(stl)) {
        cout << p << endl;
    }

即,给出始末位置和要找的符号,find()会返回出符号所在位置的地址(第一个出现的)。
这里有个神奇的地方:

cout<<*p; cout<<p;

分别输出:c.biancheng.net/stl/和c。
或者:

 //find() 函数作用于容器
    std::vector<int> myvector{ 10,20,30,40,50 };
    std::vector<int>::iterator it;
    it = find(myvector.begin(), myvector.end(), 30);
    if (it != myvector.end())
        cout << "查找成功:" << *it;
    else
        cout << "查找失败";
    return 0;

找不到的话,迭代器it会指向vector的end()地址。
但是string:
在这里插入图片描述
不能用迭代器it来保存。
详情请看这位大佬:

https://www.cnblogs.com/wkfvawl/p/9429128.html

2.ctype.h标准库

ctype.h

AC代码:

#include<iostream>
#include <string>
using namespace std;
int main() {
	string s1, s2, s3="";
	cin >> s1 >> s2;
	for (auto a : s1) {
		if (s2.find(a) == string::npos && s3.find(toupper(a)) == string::npos)
		{
			s3 += toupper(a);
		}
	}
	cout << s3;
	return 0;
}
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值