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;
- vector<int> split(string str, char sep) {
- stringstream s(str);
- vector<int> v;
- string n;
- while (getline(s, n, sep)) {
- v.push_back(stoi(n));
- }
- return v;
- }
- int main() {
- int number, index = 0, houseCount = 0;
- string line, command;
- getline(cin, line);
- vector<int> houses = split(line, '@');
- cin >> command;
- while (command != "Love!") {
- cin >> number;
- index += int(number);
- if (index >= houses.size()) {
- index = 0;
- }
- if (houses[index] == 0) {
- cout << "Place " << index << " already had Valentine's day.\n";
- }
- else {
- houses[index] -= 2;
- if (houses[index] == 0) {
- cout << "Place " << index << " has Valentine's day.\n";
- }
- }
- cin >> command;
- }
- for (int i = 0; i < houses.size(); i++) {
- if (houses[i] > 0) {
- houseCount++;
- }
- }
- cout << "Cupid's last position was " << index << ".\n";
- if (houseCount == 0) {
- cout << "Mission was successful.\n";
- }
- else {
- cout << "Cupid has failed " << houseCount << " places.\n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement