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) .前者更优秀

全部评论

相关推荐

牛客41406533...:回答他在课上学,一辈子待在学校的老教授用三十年前的祖传PPT一字一句的讲解,使用谭浩强红皮书作为教材在devc++里面敲出a+++++a的瞬间爆出114514个编译错误来学这样才显得专业
点赞 评论 收藏
分享
自来熟的放鸽子能手面...:这个不一定,找hr跟进一下
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务