Click here to Skip to main content
15,891,828 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
#include<iostream>
#include<vector>
#include<stdlib.h>
#include<string>
#include<map>
#include<queue>
#include<algorithm>
using namespace std;

int main()
{
	int n,k;
	cin >> n>>k;
	vector<int> step(k);
	vector<int> child(n);
	vector<int> res;
	for (int i = 0; i < k; i++)
	{
		cin >> step[i];
	}
	for (int i = 0; i < n; i++)
		child[i] = i + 1;
	int cnt = 0;
	int head =0;
	while (cnt != k)
	{
		int s = step[cnt];
		head = (head + s) % n;
		res.push_back(child[head]);
		for (int j = head; j < n - 1; j++)
			child[j] = child[j + 1];
		n--;
		cnt++;
	}
	for (int i = 0; i < res.size(); i++)
	{
		cout << res[i];
		if (i != res.size() - 1)
			cout << " ";
	}
	cout << endl;
	return 0;
}


What I have tried:

#include<iostream>
#include<vector>
#include<stdlib.h>
#include<string>
#include<map>
#include<queue>
#include<algorithm>
using namespace std;

int main()
{
	int n,k;
	cin >> n>>k;
	vector<int> step(k);
	vector<int> child(n);
	vector<int> res;
	for (int i = 0; i < k; i++)
	{
		cin >> step[i];
	}
	for (int i = 0; i < n; i++)
		child[i] = i + 1;
	int cnt = 0;
	int head =0;
	while (cnt != k)
	{
		int s = step[cnt];
		head = (head + s) % n;
		res.push_back(child[head]);
		for (int j = head; j < n - 1; j++)
			child[j] = child[j + 1];
		n--;
		cnt++;
	}
	for (int i = 0; i < res.size(); i++)
	{
		cout << res[i];
		if (i != res.size() - 1)
			cout << " ";
	}
	cout << endl;
	return 0;
}
Posted
Updated 20-Oct-18 6:47am
Comments
Patrice T 20-Oct-18 3:56am    
What range ?
OriginalGriff 20-Oct-18 3:56am    
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with. Just dumping the same code on us twice without any explanation of what the problem is other than "set the range to a larger range" doesn't tell us anything about the problem you are having. And if we don't understand the problem, we can't help you fix it!
So stop trying to type as little as possible and explain in English what the problem is, what you have tried, what happened when you tried it, where you are stuck, and what help you need.


Use the "Improve question" widget to edit your question and provide better information.
Andreas Gieriet 21-Oct-18 8:49am    
Hey, you obviously don't take the time to write a decent question. Simply throwing code snippets at our faces is probably not the nicest approach...
Why should we take any time to "help" you.
You want something from us, so, make it easy for us to help you!
Regards
Andi

1 solution

Your question is a bit opaque, but you can do it via including all your code into a big while loop and ask at the end for a further loop. Else you can check against some value and re ask for as bigger value.

On both way I suggest that you make more output to the user, so he knows where he is and what is the meaning of the next input. Like
C++
for (int i = 0; i < k; i++)
{
	cout << "Input for step: " << i;
	cin >> step[i];
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900