zoukankan      html  css  js  c++  java
  • C++ unordered_set运用实例

    C++ unordered_set运用实例

    #include <unordered_set>
    #include <numeric>
    #include "print.hpp"
    
    using namespace std;
    
    int main()
    {
        unordered_set<int> u_set1 = {1,2,3,5,7,11,13,17,19,23,29,31,37,41};
        PRINT_ELEMENTS(u_set1);
    
        u_set1.insert({-7,17,33,-11,17,19,23});
        PRINT_ELEMENTS(u_set1);
    
    
        u_set1.erase(33);
        PRINT_ELEMENTS(u_set1);
    
        u_set1.insert(accumulate(u_set1.begin(),u_set1.end(),0));
        PRINT_ELEMENTS(u_set1);
        
        unordered_set<int>::iterator pos1;
        for (pos1 = u_set1.begin();pos1 != u_set1.end();)
        {
            if (*pos1 <0)
            {
                pos1 = u_set1.erase(pos1);
            }
            else
            {
                ++pos1;
            }
        }
    
        PRINT_ELEMENTS(u_set1);
    
        system("pause");
        return 0;
    }

    17 1 2 19 11 3 13 5 7 23 29 31 37 41
    17 1 2 19 11 3 13 5 7 23 29 31 37 41 -7 33 -11
    17 1 2 19 11 3 13 5 7 23 29 31 37 41 -7 -11
    17 1 2 19 11 3 13 5 7 23 221 29 31 37 41 -7 -11
    17 1 2 19 11 3 13 5 7 23 221 29 31 37 41
    请按任意键继续. . .

    代码参考:C++标准库(第2版)

  • 相关阅读:
    javascript 介绍
    命令提示符(命令行)
    node(1) hello world
    用Vgg16来提取特征
    VGG16学习
    注意力模型
    统计学习方法
    数字图像处理(五)
    数字图像处理(四)
    BN
  • 原文地址:https://www.cnblogs.com/herd/p/12071845.html
Copyright © 2011-2022 走看看