Advertisement
Spocoman

7. Hot Potato

Jan 10th, 2024
1,162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <queue>
  4. #include <sstream>
  5.  
  6. using namespace std;
  7.  
  8. int main() {
  9.     string line, name;
  10.     getline(cin, line);
  11.  
  12.     istringstream ss(line);
  13.  
  14.     queue<string> names;
  15.  
  16.     while (ss >> name) {
  17.         names.push(name);
  18.     }
  19.  
  20.     int n;
  21.     cin >> n;
  22.  
  23.     while (names.size() != 1) {
  24.         for (size_t i = 1; i < n; i++) {
  25.             names.push(names.front());
  26.             names.pop();
  27.         }
  28.         cout << "Removed " << names.front() << endl;
  29.         names.pop();
  30.     }
  31.  
  32.     cout << "Last is " << names.front() << endl;
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement