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<<" ";
    }
    
  • 相关阅读:
    CSS属性中Display与Visibility的不同
    11
    【零基础学习iOS开发】【01-前言】01-开篇
    C#计算时间差。
    C++拷贝构造函数:浅拷贝与深拷贝
    C++:string操作函数
    文件输入输出(二):文件的操作
    文件输入输出(一):重定向
    Java中的StringBuffer
    C++中setiosflags()的用法
  • 原文地址:https://www.cnblogs.com/fengxunling/p/9918011.html
Copyright © 2011-2022 走看看