2个回答
展开全部
从15中选出10个有3003中选法,需要每个都输出吗?
从textBox1输入输出个数,输出到richTextBox1中
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication30
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int[] array = new int[15] { 12, 33, 45, 66, 75, 34, 56, 123, 442, 5454, 242, 234, 665, 5343, 552 };
private void button1_Click(object sender, EventArgs e)
{
lines = new List<string>();
int count = 0;
try
{
count = Convert.ToInt32(textBox1.Text);
if (count <= 0)
{
MessageBox.Show("输出个数必须大于0");
return;
}
}
catch
{
MessageBox.Show("请在TextBox中输入输出个数");
}
OutPut(count);
richTextBox1.Lines = lines.ToArray();
}
List<String> lines;
List<int> listI;
private void OutPut(int count)
{
while (lines.Count <= count)
{
Application.DoEvents();
listI = new List<int>();
String s = "";
for (int i = 0; i < 10; i++)
{
Random r = new Random();
int temp;
do
{
temp = array[r.Next(0, 15)];
} while (listI.Contains(temp));
listI.Add(temp);
}
listI.Sort();
foreach (int i in listI)
{
s += i.ToString() + " ";
}
if (!lines.Contains(s))
{
lines.Add(s);
richTextBox1.Lines = lines.ToArray();
}
}
}
}
}
从textBox1输入输出个数,输出到richTextBox1中
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication30
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int[] array = new int[15] { 12, 33, 45, 66, 75, 34, 56, 123, 442, 5454, 242, 234, 665, 5343, 552 };
private void button1_Click(object sender, EventArgs e)
{
lines = new List<string>();
int count = 0;
try
{
count = Convert.ToInt32(textBox1.Text);
if (count <= 0)
{
MessageBox.Show("输出个数必须大于0");
return;
}
}
catch
{
MessageBox.Show("请在TextBox中输入输出个数");
}
OutPut(count);
richTextBox1.Lines = lines.ToArray();
}
List<String> lines;
List<int> listI;
private void OutPut(int count)
{
while (lines.Count <= count)
{
Application.DoEvents();
listI = new List<int>();
String s = "";
for (int i = 0; i < 10; i++)
{
Random r = new Random();
int temp;
do
{
temp = array[r.Next(0, 15)];
} while (listI.Contains(temp));
listI.Add(temp);
}
listI.Sort();
foreach (int i in listI)
{
s += i.ToString() + " ";
}
if (!lines.Contains(s))
{
lines.Add(s);
richTextBox1.Lines = lines.ToArray();
}
}
}
}
}
展开全部
这么写就行
private void button1_Click(object sender, EventArgs e)
{
List<int> list = new List<int>(new int[15] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 });
List<int> result = new List<int>();
Random random = new Random();
while (list.Count > 5)
{
int index = random.Next(0, list.Count);
result.Add(list[index]);
list.RemoveAt(index);
}
result.Sort();
foreach (int var in result)
{
MessageBox.Show(var.ToString());
}
}
private void button1_Click(object sender, EventArgs e)
{
List<int> list = new List<int>(new int[15] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 });
List<int> result = new List<int>();
Random random = new Random();
while (list.Count > 5)
{
int index = random.Next(0, list.Count);
result.Add(list[index]);
list.RemoveAt(index);
}
result.Sort();
foreach (int var in result)
{
MessageBox.Show(var.ToString());
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询