110,566
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace ch5_6
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public class people
{
public void getjumpnum(int personnum, out int[] jumpnum)
{
jumpnum = new int[personnum+1];//定义personnum数组
int i,n=0, flag=0,k=1;
int[] j = new int[personnum + 1];//定义局部变量
for (i = 1; i <=personnum; i++)
{
j[i] = 1;//表示该位置上未跳水
}
for (i = 1; i <= personnum+1; i++)
{
if (i == personnum+1)//当i超过人数,给i初始化1
i = 1;
flag += j[i];
if (flag == 7)
{ n++; j[i] = 0; jumpnum[k++] = i; flag = 0; }// j[i] = 0表示该位置上跳水, jumpnum[k++] = i记录位置,flag初始化
if (n == personnum)//n来控制循环
break ;
}
}
}
private void button1_Click(object sender, EventArgs e)
{
int i, personnum;
int[] p;
people jump = new people();
personnum = Convert.ToInt16(textBox1.Text);
jump.getjumpnum(personnum, out p);
for (i= 1; i <= personnum;i++ )
{
textBox2.Text = textBox2.Text + " " + p[i].ToString();
}
}
}
}
void SortIt(int _num, int[] its, out ArrayList _jumpSort)
{
_jumpSort = new ArrayList();
int i = 0, j = 0;
while (_jumpSort.Count != its.Length)
{
j = (j == its.Length) ? 0 : j;
if (its[j] == -1)
{
j++;
continue;
}
if (i == _num)
{
i = -1;
its[j] = -1;
_jumpSort.Add(j);
}
i++;
j++;
}
}