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;
- 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") {
- int index, value;
- cin >> index >> value;
- if (command == "Shoot") {
- if (index >= 0 && index < targets.size()) {
- targets[index] -= value;
- if (targets[index] <= 0) {
- targets.erase(targets.begin() + index);
- }
- }
- }
- else if (command == "Add") {
- if (index >= 0 && index < targets.size()) {
- targets.insert(targets.begin() + index, value);
- }
- else {
- cout << "Invalid placement!\n";
- }
- }
- else if (command == "Strike") {
- if (index - value >= 0 && index + value < targets.size()) {
- targets.erase(targets.begin() + index - value, targets.begin() + value + index + 1);
- }
- else {
- cout << "Strike missed!\n";
- }
- }
- cin >> command;
- }
- for (int i = 0; i < targets.size(); i++) {
- cout << targets[i] << (i < targets.size() - 1 ? "|" : "");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement