Advertisement
Spocoman

03. Heart Delivery

Nov 9th, 2023
739
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.35 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. vector<int> split(string str, char sep) {
  10.     stringstream s(str);
  11.     vector<int> v;
  12.     string n;
  13.     while (getline(s, n, sep)) {
  14.         v.push_back(stoi(n));
  15.     }
  16.     return v;
  17. }
  18.  
  19. int main() {
  20.     int number, index = 0, houseCount = 0;
  21.  
  22.     string line, command;
  23.     getline(cin, line);
  24.  
  25.     vector<int> houses = split(line, '@');
  26.  
  27.     cin >> command;
  28.  
  29.     while (command != "Love!") {
  30.         cin >> number;
  31.         index += int(number);
  32.         if (index >= houses.size()) {
  33.             index = 0;
  34.         }
  35.         if (houses[index] == 0) {
  36.             cout << "Place " << index << " already had Valentine's day.\n";
  37.         }
  38.         else {
  39.             houses[index] -= 2;
  40.             if (houses[index] == 0) {
  41.                 cout << "Place " << index << " has Valentine's day.\n";
  42.             }
  43.         }
  44.         cin >> command;
  45.     }
  46.  
  47.     for (int i = 0; i < houses.size(); i++) {
  48.         if (houses[i] > 0) {
  49.             houseCount++;
  50.         }
  51.     }
  52.  
  53.     cout << "Cupid's last position was " << index << ".\n";
  54.     if (houseCount == 0) {
  55.         cout << "Mission was successful.\n";
  56.     }
  57.     else {
  58.         cout << "Cupid has failed " << houseCount << " places.\n";
  59.     }
  60.     return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement