Advertisement
Spocoman

02. Shoot for the Win

Nov 8th, 2023
799
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.12 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 n, index, shotTargets = 0;
  11.     string line;
  12.     getline(cin, line);
  13.  
  14.     istringstream stream(line);
  15.  
  16.     vector<int> targets;
  17.  
  18.     while (stream >> n) {
  19.         targets.push_back(n);
  20.     }
  21.  
  22.     string command;
  23.     cin >> command;
  24.  
  25.     while (command != "End") {
  26.         index = stoi(command);
  27.  
  28.         if (index >= 0 && index < targets.size()) {
  29.             for (int i = 0; i < targets.size(); i++) {
  30.                 if (targets[i] != -1 && index != i) {
  31.                     if (targets[i] > targets[index]) {
  32.                         targets[i] -= targets[index];
  33.                     }
  34.                     else {
  35.                         targets[i] += targets[index];
  36.                     }
  37.                 }
  38.             }
  39.             targets[index] = -1;
  40.             shotTargets++;
  41.         }
  42.  
  43.         cin >> command;
  44.     }
  45.  
  46.     cout << "Shot targets: " << shotTargets << " -> ";
  47.     for (auto& t: targets) {
  48.         cout << t << ' ';
  49.     }
  50.     return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement