Advertisement
Guest User

Untitled

a guest
Dec 11th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1. #include <vector>
  2. #include <iostream>
  3. #include <stdio.h>
  4.  
  5. using namespace std;
  6.  
  7. long elementsSum(const std::vector<std::vector<int> >& arr, int d = 0){
  8.   //your code here
  9.    
  10.     long sum = 0;
  11.     int indice = arr.size() - 1;
  12.    
  13.     for(int i = 0; i < arr.size(); i++) {
  14.        
  15.         if(arr[i].size() > 0 &&  indice >= 0 && indice  < arr[i].size()) {
  16.             sum += arr[i][indice]; 
  17.         }
  18.         else {
  19.             sum += d;
  20.         }
  21.         indice--;
  22.     }
  23.    
  24.     return sum ;
  25.  
  26. }
  27.  
  28. int main() {
  29.    
  30.     std::vector<std::vector<int> > v;
  31.     std::vector<int> aux1;
  32.     aux1.push_back(-5);
  33.     aux1.push_back(-7);
  34.     aux1.push_back(-9);
  35.    
  36.     std::vector<int> aux2;
  37.     aux2.push_back(-90);
  38.     aux2.push_back(-22);
  39.     aux2.push_back(-10);
  40.    
  41.     v.push_back(aux1);
  42.     v.push_back(aux2);
  43.    
  44.     cout << elementsSum(v, 1) << endl;
  45.    
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement