如何将范围设置为更大的范围? [英] How to set the range to a larger range?

查看:99
本文介绍了如何将范围设置为更大的范围?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#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;
}

推荐答案

您的问题有点不透明,但您可以通过将所有代码包含在一起来实现循环并在最后询问进一步的循环。否则你可以检查一些价值,并要求更大的价值。



我想建议你向用户提供更多输出,所以他知道他在哪里是和下一个输入的含义是什么。像
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
for (int i = 0; i < k; i++)
{
	cout << "Input for step: " << i;
	cin >> step[i];
}


这篇关于如何将范围设置为更大的范围?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆