• 26.不改变数据的数值算法


    • 对容器进行填充  
      1 void show(int x)
      2 {
      3     cout << x << endl;
      4 }
      1 int a[10];
      2     //指定一个数据开始,对a进行填充
      3     iota(a, a + 10, 1);
      4 
      5     for_each(a, a + 10, show);
    • 容器两个元素进行计算
      1 //数组两个元素计算
      2     cout << accumulate(a, a + 10, -1, [](int x, int y) {return x * y; }) << endl;
    • 内积
      1     int a1[3] = { 1,2,3 };
      2     int b1[3] = { 4,5,6 };
      3     //实现两个数组对应的位置相乘,然后相加,(内积)最后边的0是计算完再加一个0
      4     int res = inner_product(a1, a1 + 3, b1, 0);
      5     cout << res << endl;
    • 乘方
      1 cout << pow(2, 10) << endl;
    • 求相邻元素之差与之积
      1 int a2[5] = { 1,12,3,14,5 };
      2         int res[5];
      3         //求相邻元素之差
      4         adjacent_difference(a2, a2 + 5, res);
      5         for_each(res, res + 5, [](int x) {cout << x << endl; });
      6         //求相邻元素之积
      7         adjacent_difference(a2, a2 + 5, res, [](int a, int b) {return a * b; });
    • 求一个容器的和与积,并把过程保存在一个数组中
       1 int a[5] = { 1,23,4,5,6 };
       2         int v[5];
       3         //计算和到v中
       4         partial_sum(a, a + 5, v);
       5 
       6         for_each(v, v + 5, [](int x) {cout << x << endl; });
       7 
       8         //计算积到v中
       9         partial_sum(a, a + 5, v, [](int a,int b) {return a*b});
      10 
      11         for_each(v, v + 5, [](int x) {cout << x << endl; });
  • 相关阅读:
    查看端口有没有被占用
    微信公众号2()
    How to insert a segment of noise to music file
    puppet practice
    Docker Commands
    LempelZiv algorithm realization
    The algorithm of entropy realization
    Java network programmingguessing game
    Deploy Openstack with RDO and Change VNC console to Spice
    puppet overview
  • 原文地址:https://www.cnblogs.com/xiaochi/p/8643861.html
Copyright © 2020-2023  润新知