zoukankan      html  css  js  c++  java
  • [C++] algorithm Know unknown

    std::max_element

    #include <algorithm>
    #include <iostream>
    #include <vector>
    #include <cmath>
     
    static bool abs_compare(int a, int b)
    {
        return (std::abs(a) < std::abs(b));
    }
     
    int main()
    {
        std::vector<int> v{ 3, 1, -14, 1, 5, 9 }; 
        std::vector<int>::iterator result;
     
        result = std::max_element(v.begin(), v.end());
        std::cout << "max element at: " << std::distance(v.begin(), result) << '
    ';
     
        result = std::max_element(v.begin(), v.end(), abs_compare);
        std::cout << "max element (absolute) at: " << std::distance(v.begin(), result);
    }


    max element at: 5
    max element (absolute) at: 2


    std::distance

    #include <iostream>
    #include <iterator>
    #include <vector>
     
    int main() 
    {
        std::vector<int> v{ 3, 1, 4 };
        std::cout << "distance(first, last) = "
                  << std::distance(v.begin(), v.end()) << '
    '
                  << "distance(last, first) = "
                  << std::distance(v.end(), v.begin()) << '
    ';
    }

    distance(first, last) = 3
    distance(last, first) = -3

    std::reverse

    #include <vector>
    #include <iostream>
    #include <iterator>
    #include <algorithm>
     
    int main()
    {
        std::vector<int> v({1,2,3});
        std::reverse(std::begin(v), std::end(v));
        std::cout << v[0] << v[1] << v[2] << '
    ';
     
        int a[] = {4, 5, 6, 7};
        std::reverse(std::begin(a), std::end(a));
        std::cout << a[0] << a[1] << a[2] << a[3] << '
    ';
    }
  • 相关阅读:
    java
    JAVA的String 类
    JAVA的StringBuffer类
    TestLink 的使用详解
    Vertrigo Serv + testlink 环境搭建
    自动化测试全聚合
    selenium -文件上传的实现 -对于含有input element的上传
    chrome启动参数设置
    selenium
    java
  • 原文地址:https://www.cnblogs.com/zhanxiage1994/p/6963814.html
Copyright © 2011-2022 走看看