1.判断vector只出现过一次的数字用异或
string用find和rfind
2.判断多数元素 先排序然后取a[length/2]的元素
3.vector中的删除元素
利用迭代器find!!!!!!
vector<int>a;
int target; //要删除的值
for(vector<int>::iterator it=a.begin();it!=a.end();)
{
if((*it)==target)
{
it=a.erase(it);
}
else
it++;
}
4.reverse函数能反转字符,数组
string temp="temp";
reverse(temp.begin(),temp.end()); //此时temp输出为 pmet
5.#include<cctype>中的函数
isdigit() 判断是否为数字
isalpha() 判断是否为字母
isalnum() 判断是否为字母或数字
islower() 判断是否为小写字母
isupper() 判断是否为大写字母
6.string中的find()
可以指定位置进行查找
string temp="Hello world";
int a=temp.find('l',5); //从第五位以后开始查找
可以查找第一次出现的位置和最后一次出现的位置
string temp="hello world";
cout<<temp.find_first_of('h'); // 第一次出现的位置
cout<<temp.find_last_of('h'); // 最后一次出现的位置
本文介绍了C++中几种高效的数据处理方法,包括使用异或操作找出vector中只出现一次的数字,利用find和rfind进行字符串查找,通过排序确定多数元素,以及如何使用迭代器删除vector中的特定元素。同时,还提到了标准库中的字符串函数如isdigit和isalpha等,以及string的find方法在不同场景下的应用。
1176

被折叠的 条评论
为什么被折叠?



