例如:
一组为:一,二三,四五六,七,九十。
另一组:你好,他好,塔塔,你好,拜拜,再见。
然后组合成指定长度。
如:
一你好塔塔二三你好
拜拜七他好四五六一
再见他好四五六九十
这种应该用什么方法实现?蒙圈中,小白一枚,求大神指点。
例如:
一组为:一,二三,四五六,七,九十。
另一组:你好,他好,塔塔,你好,拜拜,再见。
然后组合成指定长度。
如:
一你好塔塔二三你好
拜拜七他好四五六一
再见他好四五六九十
这种应该用什么方法实现?蒙圈中,小白一枚,求大神指点。
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 Q753166
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string[] grp1 = textBox1.Text.Split(',');
string[] grp2 = textBox2.Text.Split(',');
string rnd = "";
while (true)
{
rnd += grp1.Union(grp2).OrderBy(x => Guid.NewGuid()).First();
if (rnd.Length > int.Parse(textBox3.Text)) rnd = "";
if (rnd.Length == int.Parse(textBox3.Text)) break;
}
listBox1.Items.Add(rnd);
}
}
}
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 Q753166
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string[] grp1 = textBox1.Text.Split(',');
string[] grp2 = textBox2.Text.Split(',');
string rnd = "";
while (true)
{
var grp = grp1.OrderBy(x => Guid.NewGuid()).Take(2).Concat(grp2.OrderBy(x => Guid.NewGuid()).Take(2));
rnd = string.Join("", grp.OrderBy(x => Guid.NewGuid()));
if (rnd.Length == int.Parse(textBox3.Text)) break;
}
listBox1.Items.Add(rnd);
}
}
}
namespace Q753166
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.textBox3 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.listBox1 = new System.Windows.Forms.ListBox();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(12, 12);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(259, 20);
this.textBox1.TabIndex = 0;
this.textBox1.Text = "一,二三,四五六,七,九十";
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(12, 38);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(259, 20);
this.textBox2.TabIndex = 1;
this.textBox2.Text = "你好,他好,塔塔,你好,拜拜,再见";
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(9, 67);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(34, 13);
this.label1.TabIndex = 2;
this.label1.Text = " 长度";
//
// textBox3
//
this.textBox3.Location = new System.Drawing.Point(53, 64);
this.textBox3.Name = "textBox3";
this.textBox3.Size = new System.Drawing.Size(218, 20);
this.textBox3.TabIndex = 3;
this.textBox3.Text = "9";
//
// button1
//
this.button1.Location = new System.Drawing.Point(12, 90);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(79, 24);
this.button1.TabIndex = 4;
this.button1.Text = "生成";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// listBox1
//
this.listBox1.FormattingEnabled = true;
this.listBox1.Location = new System.Drawing.Point(12, 120);
this.listBox1.Name = "listBox1";
this.listBox1.Size = new System.Drawing.Size(259, 355);
this.listBox1.TabIndex = 5;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(283, 486);
this.Controls.Add(this.listBox1);
this.Controls.Add(this.button1);
this.Controls.Add(this.textBox3);
this.Controls.Add(this.label1);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.textBox1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox textBox3;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.ListBox listBox1;
}
}