GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — STLSourceCodeNote/6_STL_algorithms/6_3_1_numeric.cpp at master · SilverMaple/STLSourceCodeNote Expand file tree/ Copy path6_3_1_numeric.cppMore file actions 54 lines (41 loc) · 1.44 KB / Copy path6_3_1_numeric.cppFile metadata and controls54 lines (41 loc) · 1.44 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 // file: 6numeric.cpp #include <numeric> #include <vector> #include <functional> // minus<int>() #include <iostream> // ostream_iterator #include <iterator> using namespace std; int main() { int ia[5] = {1, 2, 3, 4, 5}; vector<int> iv(ia, ia + 5); // 0+1+2+3... cout << accumulate(iv.begin(), iv.end(), 0) << endl; // 0-1-2-3 cout << accumulate(iv.begin(), iv.end(), 0, minus<int>()) << endl; // 10 + 1*1 + 2*2 + ... cout << inner_product(iv.begin(), iv.end(), iv.begin(), 10) << endl; // 10 - 1+1 - 2+2 - ... cout << inner_product(iv.begin(), iv.end(), iv.begin(), 10, minus<int>(), plus<int>()) << endl; // 将迭代器绑定到cout,作为输出用 ostream_iterator<int> oite(cout, " "); // 1 3 6 10 15 累计和 partial_sum(iv.begin(), iv.end(), oite); cout << endl; // 1 -1 -4 -8 -13 累计差 partial_sum(iv.begin(), iv.end(), oite, minus<int>()); cout << endl; // 1 1 1 1 1 new #n = #n - #n-1 adjacent_difference(iv.begin(), iv.end(), oite); cout << endl; // 1 3 5 7 9 new #n = op(#n, #n-1) adjacent_difference(iv.begin(), iv.end(), oite, plus<int>()); cout << endl; // mingw c++ 中stl没有power实现 // cout << power(10, 3) << endl; // cout << power(10, 3, plus<int>()) << endl; int n = 3; iota(iv.begin(), iv.end(), n); // 填入n, n+1, n+2 for (int i = 0; i < iv.size(); ++i) cout << iv[i] << ' '; } |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |