zoukankan      html  css  js  c++  java
  • 一些可能很常用的函数介绍(持续更新)

    咕咕咕qwqwq

    一些次常用的函数介绍:

    • replace
    replace(初始位置,结束位置,替换字符串);
    
    • find
    (母字符串).find(子字符串,起始位置)
    

    如果没有设置起始位置默认为从头开始。如果返回-1的话表示该字符串中没有查询的字符串出现。qwq
    当然,如果读入的时候往右移动了一位,记得起始位置也要变一变qwqwq

    • random_shuffle()
    random_shuffle(起始位置,结束位置)
    

    将数组打乱。

    • nth_element()
    nth_element(起始位置,所求位置,结束位置)
    

    数组下表从零开始,nth_element(a,a+k,a+n),表示要把第k大的数放到下标为k的位置上。
    时间复杂度为O(N),比所求数小的数都在这个数前面,比所求数大的数都在这个数后面,但是不保证有序。
    最大的应用价值为求中位数

    • set_union() 求并集
    • set_intersection() 求交集
    #include<iostream>
    #include<set>
    #include<iterator>
    #include<algorithm>
    using namespace std;
    int main()
    {
    	set<int>s1,s2,s3,s4;
    	s1.insert(1);
    	s1.insert(2);
    	s2.insert(2);
    	s2.insert(4);
    	set_union(s1.begin(),s1.end(),s2.begin(),s2.end(),inserter(s3,s3.begin()));
    	set_intersection(s1.begin(),s1.end(),s2.begin(),s2.end(),inserter(s4,s4.begin()));
    	for(set<int>::iterator it=s3.begin();it!=s3.end();it++)
    		cout<<*it<<" ";
    	cout<<endl;
    	for(set<int>::iterator it=s4.begin();it!=s4.end();it++)
    		cout<<*it<<" ";
    }
    
  • 相关阅读:
    线程,协程
    python魔法方法详解
    Sorted方法排序用法
    time模块
    Haroopad安装与配置: Linux系统下最好用的Markdown编辑器
    C++ Primer第五版答案
    Ubuntu14.04安装有道词典(openyoudao)
    Ubuntu14.04下Sublime Text 3解决无法输入中文
    OpenLTE安装教程
    GNU Radio: Overview of the GNU Radio Scheduler
  • 原文地址:https://www.cnblogs.com/fengxunling/p/9918011.html
Copyright © 2011-2022 走看看