zoukankan      html  css  js  c++  java
  • STL

    Array是C++ 11给STL新增加的容器

    ArrayTest.cpp

    #include <array>
    #include <algorithm>
    #include <functional>
    #include <numeric>
    #include "../../Core/print.hpp"
    #include "ArrayTest.h"
    
    using namespace std;
    
    void ArrayTest::simpleOperation()
    {
        // create array with 10 ints
        array<int, 10> a = { 11, 22, 33, 44 };
    
        PRINT_ELEMENTS(a);
    
        // modify last two elements
        a.back() = 9999999;
        a[a.size() - 2] = 42;
        PRINT_ELEMENTS(a);
    
        // process sum of all elements
        cout << "sum: "
            << accumulate(a.begin(), a.end(), 0)
            << endl;
    
        // negate all elements
        transform(a.begin(), a.end(),    // source
            a.begin(),            // destination
            negate<int>());       // operation
        PRINT_ELEMENTS(a);
    }
    
    void ArrayTest::run()
    {
        printStart("simpleOperation()");
        simpleOperation();
        printEnd("simpleOperation()");
    }

    运行结果:

    ---------------- simpleOperation(): Run Start ----------------
    11 22 33 44 0 0 0 0 0 0
    11 22 33 44 0 0 0 0 42 9999999
    sum: 10000151
    -11 -22 -33 -44 0 0 0 0 -42 -9999999
    ---------------- simpleOperation(): Run End ----------------

  • 相关阅读:
    4.23计算机网络
    CF436F Banners
    CF1467C Three Bags
    LG P3247 [HNOI2016]最小公倍数
    LG P5473 [NOI2019] I 君的探险
    LG P3261 [JLOI2015]城池攻占
    LG P4149 [IOI2011]Race
    LG P3181 [HAOI2016]找相同字符
    SP7258 SUBLEX
    SP1811 LCS
  • 原文地址:https://www.cnblogs.com/davidgu/p/4872095.html
Copyright © 2011-2022 走看看