Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <sstream>
- #include <queue>
- using namespace std;
- queue <int> split (const string &s, char delim) {
- queue <int> result;
- stringstream ss(s);
- string item;
- while (getline(ss, item, delim)){
- result.push(stoi(item));
- }
- return result;
- }
- int solve(int n, int k){
- if (n == 1)
- return 1;
- else
- return (solve(n - 1, k) + k-1) % n + 1;
- }
- int main(){
- string str;
- getline(cin, str);
- queue <int> q = split(str, ' ');
- int n = q.front(); q.pop();
- while(!q.empty()){
- int temp = q.front(); q.pop();
- cout << solve(n, temp) << " ";
- }
- cout << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement