Move History

Fork Selected
  • Code
    #include<numeric>
    #include<stdint.h>
    #include<vector>
    
    int64_t add_arr(const std::vector<int32_t> &arr) {
      return std::reduce(arr.cbegin(), arr.cend(), 0);
    }
    Test Cases
    #include <vector>
    #include <criterion/criterion.h>
    
    int64_t add_arr(const std::vector<int32_t> &arr);
    
    Test(add_arr, all)
    {
      std::vector<int> arr = {1, 2, 3, 4, 5, 6, 7, 8, 9};
      cr_assert_eq(add_arr(arr), 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9);
    
      std::vector<int> arr2 = {1, -2, 3, 4, 5, 6, 7, 8, 9};
      cr_assert_eq(add_arr(arr2), 1 + (-2) + 3 + 4 + 5 + 6 + 7 + 8 + 9);
    }
  • Code
    • #include<bits/stdc++.h>
    • using namespace std;
    • #include<numeric>
    • #include<stdint.h>
    • #include<vector>
    • long add_arr(vector<int> arr)
    • {
    • long sum = 0;
    • for(int i = 0; i < arr.size(); i++) {
    • sum += arr[i];
    • }
    • return sum;
    • int64_t add_arr(const std::vector<int32_t> &arr) {
    • return std::reduce(arr.cbegin(), arr.cend(), 0);
    • }
    Test Cases
    • #include <vector>
    • #include <criterion/criterion.h>
    • long add_arr(std::vector<int> arr);
    • int64_t add_arr(const std::vector<int32_t> &arr);
    • Test(add_arr, all)
    • {
    • std::vector<int> arr = {1, 2, 3, 4, 5, 6, 7, 8, 9};
    • cr_assert_eq(add_arr(arr), 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9);
    • std::vector<int> arr2 = {1, -2, 3, 4, 5, 6, 7, 8, 9};
    • cr_assert_eq(add_arr(arr2), 1 + (-2) + 3 + 4 + 5 + 6 + 7 + 8 + 9);
    • }