Advertisement
Spocoman

02. Array Modifier

Nov 7th, 2023
603
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.16 KB | None | 0 0
  1. #include <iostream>
  2. #include <sstream>
  3. #include <string>
  4. #include <vector>
  5. #include <algorithm>
  6.  
  7. using namespace std;
  8.  
  9. int main() {
  10.     int number;
  11.  
  12.     string line;
  13.     getline(cin, line);
  14.  
  15.     istringstream stream(line);
  16.  
  17.     vector<int> numbers;
  18.  
  19.     while (stream >> number) {
  20.         numbers.push_back(number);
  21.         sumNumbers += number;
  22.     }
  23.  
  24.     string command;
  25.     cin >> command;
  26.  
  27.     int index1, index2;
  28.  
  29.     while (command != "end") {
  30.         if (command == "decrease") {
  31.             for (int i = 0; i < numbers.size(); i++) {
  32.                 numbers[i]--;
  33.             }
  34.         }
  35.         else {          
  36.             cin >> index1 >> index2;
  37.  
  38.             if (command == "swap") {
  39.                 int value = numbers[index1];
  40.                 numbers[index1] = numbers[index2];
  41.                 numbers[index2] = value;
  42.             }
  43.             else {
  44.                 numbers[index1] *= numbers[index2];
  45.             }
  46.         }
  47.         cin.ignore();
  48.         cin >> command;
  49.     }
  50.  
  51.     for (int i = 0; i < numbers.size(); i++) {
  52.         cout << numbers[i] << (i < numbers.size() - 1 ? ", " : "");
  53.     }
  54.     return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement