Advertisement
Infernale

NCTU LAB 14/11 NUM 4

Nov 14th, 2019
517
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. #include <iostream>
  2. #include <sstream>
  3. #include <queue>
  4. using namespace std;
  5.  
  6. queue <int> split (const string &s, char delim) {
  7.     queue <int> result;
  8.     stringstream ss(s);
  9.     string item;
  10.     while (getline(ss, item, delim)){
  11.         result.push(stoi(item));
  12.     }
  13.     return result;
  14. }
  15.  
  16. int solve(int n, int k){
  17.   if (n == 1)
  18.     return 1;
  19.   else
  20.     return (solve(n - 1, k) + k-1) % n + 1;
  21. }
  22.  
  23. int main(){
  24.   string str;
  25.   getline(cin, str);
  26.   queue <int> q = split(str, ' ');
  27.   int n = q.front(); q.pop();
  28.   while(!q.empty()){
  29.     int temp = q.front(); q.pop();
  30.     cout << solve(n, temp) << " ";
  31.   }
  32.   cout << endl;
  33.   return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement