Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <sstream>
- #include <string>
- #include <vector>
- #include <algorithm>
- using namespace std;
- int main() {
- int n, index, shotTargets = 0;
- string line;
- getline(cin, line);
- istringstream stream(line);
- vector<int> targets;
- while (stream >> n) {
- targets.push_back(n);
- }
- string command;
- cin >> command;
- while (command != "End") {
- index = stoi(command);
- if (index >= 0 && index < targets.size()) {
- for (int i = 0; i < targets.size(); i++) {
- if (targets[i] != -1 && index != i) {
- if (targets[i] > targets[index]) {
- targets[i] -= targets[index];
- }
- else {
- targets[i] += targets[index];
- }
- }
- }
- targets[index] = -1;
- shotTargets++;
- }
- cin >> command;
- }
- cout << "Shot targets: " << shotTargets << " -> ";
- for (auto& t: targets) {
- cout << t << ' ';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement