Ilya_konstantinov

Untitled

Oct 3rd, 2025 (edited)
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.97 KB | Source Code | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cstdint>
  4. #include <algorithm>
  5. #include <string>
  6. #include <cassert>
  7. #include "vector.h"
  8.  
  9. void Info(const MyVector &vector) {
  10.     std::cout << vector.Sum() << ' '
  11.               << std::setprecision(4) << std::fixed
  12.               << vector.Mean() << ' '
  13.               << vector.Min() << ' '
  14.               << vector.Max() << '\n';
  15. }
  16.  
  17. void CopyReverse(MyVector v) {
  18.     std::reverse(v.Begin(), v.End());
  19.     std::cout << v << '\n';
  20. }
  21.  
  22. void CheckSlice(MyVector v) {
  23.     (*v(0, 0).Begin()) = 6;
  24.     assert(v[0] == 6);
  25. }
  26.  
  27. int main() {
  28.     int n, m;
  29.     std::cin >> n >> m;
  30.     MyVector vec(n);
  31.     std::cin >> vec;
  32.     static_assert(sizeof(vec(0, 0)) <= 16);
  33.     CopyReverse(vec);
  34.  
  35.     int x = vec[0];
  36.     CheckSlice(vec);
  37.     assert(vec[0] == x);
  38.  
  39.  
  40.     std::string cmd;
  41.     while (m--) {
  42.         std::cin >> cmd;
  43.         if (cmd == "add") {
  44.             size_t index;
  45.             int32_t x;
  46.             std::cin >> index >> x;
  47.             if (index != 0) {
  48.                 vec.Insert(x, vec.Begin() + index - 1);
  49.             } else {
  50.                 vec.PushBack(x);
  51.             }
  52.         } else if (cmd == "remove") {
  53.             size_t index;
  54.             std::cin >> index;
  55.             if (index != 0) {
  56.                 vec.Erase(vec.Begin() + index - 1);
  57.             } else {
  58.                 vec.PopBack();
  59.             }
  60.         } else if (cmd == "get") {
  61.             ssize_t index; std::cin >> index;
  62.             std::cout << vec[index] << '\n';
  63.         } else if (cmd == "subget") {
  64.             ssize_t l, r; std::cin >> l >> r;
  65.             std::cout << vec(l, r) << '\n';
  66.         } else if (cmd == "concat") {
  67.             size_t m; std::cin >> m;
  68.             MyVector other(m);
  69.             std::cin >> other;
  70.             vec ^= other;
  71.         } else if (cmd == "info") {
  72.             Info(vec);
  73.         }
  74. #ifdef DEBUG
  75.         std::cout << vec << '\n';
  76. #endif
  77.     }
  78.     std::cout << vec << '\n';
  79. }
Advertisement
Add Comment
Please, Sign In to add comment