Advertisement
KShah

Untitled

Nov 10th, 2021
860
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <fstream>
  2. #include <iostream>
  3. #include <cstring>
  4.  
  5. int main() {
  6.    
  7.     std::ifstream in("input.txt");
  8.    
  9.     int k = 0, x;
  10.     int* sizeArr = new int[k];
  11.     while (in >> x) {
  12.         //std::cout << x << "\n";
  13.         ++k;
  14.         int* new_sizeArr = new int[k];
  15.         std::memcpy(new_sizeArr, sizeArr, sizeof(sizeArr[0]) * (k - 1));
  16.         new_sizeArr[k - 1] = x;
  17.  
  18.         delete[] sizeArr;
  19.         sizeArr = new_sizeArr;
  20.     }
  21.  
  22.     long long size = 1, sum = 0;
  23.     int** arr = new int*[k];
  24.    
  25.     for (int i = 0; i < k; ++i) {
  26.         arr[i] = new int[sizeArr[i]];
  27.  
  28.         sum = 0;
  29.         for (int j = 0; j < sizeArr[i]; ++j) {
  30.             std::cin >> arr[i][j];
  31.             sum += arr[i][j];
  32.         }
  33.         size *= sum;
  34.     }
  35.  
  36.     std::cout << size << "\n";
  37.    
  38.     delete[] sizeArr;
  39.     for (int i = 0; i < k; ++i) {
  40.         delete[] arr[i];
  41.     }
  42.  
  43.     delete[] arr;
  44.     return 0;
  45. }
  46.  
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement