不知道该怎么定义好类,弄得好累啊。。。。
using System;using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using Microsoft.VisualBasic;
namespace p110_6跳水
{
public class getBestPosition
{
public int sum;
public void BestPosition(int number, int sum, out int[] position)
{
int i;
int flat;
this.sum = sum;
position = new int[number];
for (i = 0; i < number; i++)
{
position[i] = 1;//该位置的跳水
}
for (i = 1; i < sum + 1; i++)
{
flat = 0;
for (i = 0; i < number; i++)
{
if (position[i] == 1)
{
flat++;
if (flat % 7 == 0)//满足条件的跳水
{
position[i] = 0;//将跳了水的置0;
}
}
if (flat == i)
{
i = 1;
}
}
}
}
class Program
{
static void Main(string[] args)
{
int sum;
int number;
int i;
getBestPosition p = new getBestPosition();
Random rand = new Random();
sum = rand.Next(50);
number = sum;
int[] position = new int[sum];
p.sum = sum;
p.BestPosition(number, sum, out position);
Console.Write("跳水的顺序:");
for (i = 0; i < number; i++)
{
if (position[i] == 0)
{
Console.WriteLine(i + 1);
}
}
Console.Write("跳水的人的总数:");
Console.WriteLine(sum);
}
}
}
}
我想把跳水的一个个输出,我的类好像出了问题了,他只跳到第二遍就无法循环了,题目的要求是一堆人围成一圈,数到7的就跳水;求路过的朋友帮帮忙!