Ilya_konstantinov

Untitled

Oct 3rd, 2025 (edited)
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.16 KB | Source Code | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include "func.h"
  4.  
  5. using std::cin;
  6. using std::cout;
  7. using std::endl;
  8.  
  9. int main() {
  10.     int n, m;
  11.     cin >> n >> m;
  12.     MyVector vec;
  13.     vec.Read(n);
  14.  
  15.     char cmd;
  16.     while (m--) {
  17.         cin >> cmd;
  18.         if (cmd == '+') {
  19.             int index, x;
  20.             cin >> index >> x;
  21.             if (index != 0) {
  22.                 vec.Insert(x, index - 1);
  23.             } else {
  24.                 vec.PushBack(x);
  25.             }
  26.         } else if (cmd == '-') {
  27.             int index;
  28.             cin >> index;
  29.             if (index != 0) {
  30.                 vec.Erase(index - 1);
  31.             } else {
  32.                 vec.PopBack();
  33.             }
  34.         } else if (cmd == '?') {
  35.             cin >> cmd;
  36.             if (cmd == '+') {
  37.                 cout << vec.Sum();
  38.             } else if (cmd == '/') {
  39.                 cout << std::setprecision(4) << std::fixed
  40.                      << vec.Mean();
  41.             } else if (cmd == '<') {
  42.                 cout << vec.Min();
  43.             }  else if (cmd == '>') {
  44.                 cout << vec.Max();
  45.             }
  46.             cout << endl;
  47.         }
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment