c++ 常用STL

1.<cstdio>

1) freopen("文件名.txt","w",stdout) freopen("文件名.txt","r",stdin)

2.<string>

1)支持  operator + , ==,!=,<,>,<=,>=

2)支持getline读入

3)stoi stol stoll stoul stoull stof stod stuld to_string 

3.<algorithm>

1)random_shuflle 随机排列

2)unique去重,删除连续空格

//删除连续的某个字符,只留下1个
std::string s = "wanna go    to      space?";
    auto end = std::unique(s.begin(), s.end(), [](char l, char r){
        return std::isspace(l) && std::isspace(r) && l == r;
    });
std::sort(v.begin(), v.end()); // 1 1 2 2 3 3 3 4 4 5 5 6 7 
    auto last = std::unique(v.begin(), v.end());
    // v 现在保有 {1 2 3 4 5 6 7 x x x x x x} ,其中 'x' 为不确定
    v.erase(last, v.end()); 

3)vector合并/求交集/求差(并 - 交)

vector<int>a,b,dest;
    a.pb(1);a.pb(2);a.pb(3);a.pb(4);
    b.pb(1);b.pb(3);b.pb(4);
    set_union(a.begin(),a.end(),
                     b.begin(),b.end(),
                     inserter(dest,dest.begin()));
    for(auto t : dest)  cout <<t<<" " << endl;

4) nth_element(first,first+前多少大,end,cmp); O(N)

4.<cmath>

1) fmod(A,B)

5.<set>/ <map>

1) 注意一下set.lower_bound 和 lower_bound(begin,end) .前者更优秀

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值