fork download
  1. #include <bits/stdc++.h> // Tomasz Nowak
  2. using namespace std; // XIII LO Szczecin, Poland
  3.  
  4. template<class T>
  5. struct MyArray {
  6. int offset;
  7. vector<T> vec;
  8.  
  9. MyArray(int n, int off, T &&values = T()) {
  10. vec.resize(n, values);
  11. offset = off;
  12. }
  13.  
  14. T& operator[](int i) {
  15. i += offset;
  16. assert(0 <= i and i < int(vec.size()));
  17. return vec[i];
  18. }
  19. };
  20.  
  21. int main() {
  22. MyArray<MyArray<int>> dp(3, 1, MyArray<int>(3, 1));
  23.  
  24. for(int i = -1; i <= 1; ++i)
  25. for(int j = -1; j <= 1; ++j) {
  26. dp[i][j] = i * j;
  27. cout << i << ' ' << j << ": " << dp[i][j] << '\n';
  28. }
  29. }
  30.  
Success #stdin #stdout 0s 4524KB
stdin
Standard input is empty
stdout
-1 -1: 1
-1 0: 0
-1 1: -1
0 -1: 0
0 0: 0
0 1: 0
1 -1: -1
1 0: 0
1 1: 1