stl 函数


string转化大小写: transform

https://blog.csdn.net/o_ohello/article/details/88636667

#include<bits/stdc++.h>
#include<string> 
using namespace std;
int main()
{
    string s = "AakoOO";
    transform(s.begin(), s.end(), s.begin(), ::toupper);
    cout<<s<<endl;
    transform(s.begin(), s.end(), s.begin(), ::tolower);
    cout<<s<<endl;
    return 0;
}
 

”删除”序列中所有相邻的重复元素(只保留一个)。unique

https://www.cnblogs.com/wangkundentisy/p/9033782.html

unique删除出并非真的函数,只是被不重复的元素给占领了。

删除的是相邻的元素,所以需要先排好序。

#include<iostream>
#include<algorithm>
#include<cassert>
using namespace std;
 
static bool myfunc(int i, int j)
{
    return (i + 1) == j;
    //return i == j;
}
int main()
{
 
    vector<int> a = {1,3,3,4,5,6,6,7};
    vector<int>::iterator it_1 = a.begin();
    vector<int>::iterator it_2 = a.end();
 
    //sort(it_1,it_2);
    cout<<"去重前的 a : ";
    for(int i = 0 ; i < a.size(); i++)
        cout<<a[i];
    cout<<endl;
    //it_h = unique(it_1,it_2);
    //unique(it_1,it_2,myfunc);
    unique(it_1,it_2);
    cout<<"去重后的 a : ";
    for(int i = 0 ; i < a.size(); i++)
        cout<<a[i];
    cout<<endl;
}

 

swap函数

int main()
{
    int a = 1;
    int b = 2;
    swap(a ,b);
    cout <<a << " " << b << endl; // 2 1
}

 

 

equal_range
lower_bound函数

https://www.cnblogs.com/fnlingnzb-learner/p/6005169.html

 

fill函数

 

int v[10];
int main()
{
    fill(v,v+10,-1);
    for (int i = 0; i <10; ++i)
        printf("%d ",v[i]);

// -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
}

https://blog.csdn.net/qq_32095699/article/details/79303922?utm_medium=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.control&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.control

https://blog.csdn.net/qq_37635157/article/details/10451686

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值