組合排列的實現方法

来源:http://www.cnblogs.com/aotugx/archive/2016/10/26/5995351.html
-Advertisement-
Play Games

實現字元或數字的組合排列。例如:ab 的所有組合為: ab,ba ;ab的所有不重覆排列為:ab ...


  最近在做數據分析系統,裡面涉及到組合排列的問題,查找了很多的資料,但是感覺很多資料都是比較零散的,達不到項目需求。

後來經過一段的時間的探索,終於實現了組合排列的功能。下麵我就來簡單說說吧。

     需求描述:  

   要實現的功能就是字元或數字的組合排列。例如:ab 的所有組合為:ab,ba ;  ab的所有不重覆排列為:ab。

其實這也是彩票中常說的直選和組選。效果圖如下:

          

            

  功能實現

  這裡就不多說了,直接貼上實現代碼吧。

      1.窗體界面設計

        

         設計代碼:

         

  1 partial class FrmDemo
  2     {
  3         /// <summary>
  4         /// 必需的設計器變數。
  5         /// </summary>
  6         private System.ComponentModel.IContainer components = null;
  7 
  8         /// <summary>
  9         /// 清理所有正在使用的資源。
 10         /// </summary>
 11         /// <param name="disposing">如果應釋放托管資源,為 true;否則為 false。</param>
 12         protected override void Dispose(bool disposing)
 13         {
 14             if (disposing && (components != null))
 15             {
 16                 components.Dispose();
 17             }
 18             base.Dispose(disposing);
 19         }
 20 
 21         #region Windows 窗體設計器生成的代碼
 22 
 23         /// <summary>
 24         /// 設計器支持所需的方法 - 不要
 25         /// 使用代碼編輯器修改此方法的內容。
 26         /// </summary>
 27         private void InitializeComponent()
 28         {
 29             this.label5 = new System.Windows.Forms.Label();
 30             this.btnAll2 = new System.Windows.Forms.Button();
 31             this.btnAll3 = new System.Windows.Forms.Button();
 32             this.groupBox3 = new System.Windows.Forms.GroupBox();
 33             this.txtAll = new System.Windows.Forms.TextBox();
 34             this.label4 = new System.Windows.Forms.Label();
 35             this.btnNot3 = new System.Windows.Forms.Button();
 36             this.btnNot2 = new System.Windows.Forms.Button();
 37             this.txtnot = new System.Windows.Forms.TextBox();
 38             this.groupBox2 = new System.Windows.Forms.GroupBox();
 39             this.groupBox1 = new System.Windows.Forms.GroupBox();
 40             this.label3 = new System.Windows.Forms.Label();
 41             this.label1 = new System.Windows.Forms.Label();
 42             this.txtShow = new System.Windows.Forms.TextBox();
 43             this.lbCount = new System.Windows.Forms.Label();
 44             this.groupBox3.SuspendLayout();
 45             this.groupBox2.SuspendLayout();
 46             this.groupBox1.SuspendLayout();
 47             this.SuspendLayout();
 48             // 
 49             // label5
 50             // 
 51             this.label5.AutoSize = true;
 52             this.label5.Location = new System.Drawing.Point(13, 35);
 53             this.label5.Name = "label5";
 54             this.label5.Size = new System.Drawing.Size(65, 12);
 55             this.label5.TabIndex = 20;
 56             this.label5.Text = "輸入內容:";
 57             // 
 58             // btnAll2
 59             // 
 60             this.btnAll2.Location = new System.Drawing.Point(71, 76);
 61             this.btnAll2.Name = "btnAll2";
 62             this.btnAll2.Size = new System.Drawing.Size(90, 35);
 63             this.btnAll2.TabIndex = 15;
 64             this.btnAll2.Text = "2組合";
 65             this.btnAll2.UseVisualStyleBackColor = true;
 66             this.btnAll2.Click += new System.EventHandler(this.btnAll2_Click);
 67             // 
 68             // btnAll3
 69             // 
 70             this.btnAll3.Location = new System.Drawing.Point(165, 76);
 71             this.btnAll3.Name = "btnAll3";
 72             this.btnAll3.Size = new System.Drawing.Size(90, 35);
 73             this.btnAll3.TabIndex = 11;
 74             this.btnAll3.Text = "3組合";
 75             this.btnAll3.UseVisualStyleBackColor = true;
 76             this.btnAll3.Click += new System.EventHandler(this.btnAll3_Click);
 77             // 
 78             // groupBox3
 79             // 
 80             this.groupBox3.Controls.Add(this.label5);
 81             this.groupBox3.Controls.Add(this.btnAll2);
 82             this.groupBox3.Controls.Add(this.txtAll);
 83             this.groupBox3.Controls.Add(this.btnAll3);
 84             this.groupBox3.Location = new System.Drawing.Point(22, 189);
 85             this.groupBox3.Name = "groupBox3";
 86             this.groupBox3.Size = new System.Drawing.Size(369, 144);
 87             this.groupBox3.TabIndex = 18;
 88             this.groupBox3.TabStop = false;
 89             this.groupBox3.Text = "取所有組合";
 90             // 
 91             // txtAll
 92             // 
 93             this.txtAll.Location = new System.Drawing.Point(85, 32);
 94             this.txtAll.Name = "txtAll";
 95             this.txtAll.Size = new System.Drawing.Size(239, 21);
 96             this.txtAll.TabIndex = 12;
 97             this.txtAll.Text = "abc012";
 98             // 
 99             // label4
100             // 
101             this.label4.AutoSize = true;
102             this.label4.Location = new System.Drawing.Point(13, 30);
103             this.label4.Name = "label4";
104             this.label4.Size = new System.Drawing.Size(65, 12);
105             this.label4.TabIndex = 19;
106             this.label4.Text = "輸入內容:";
107             // 
108             // btnNot3
109             // 
110             this.btnNot3.Location = new System.Drawing.Point(167, 59);
111             this.btnNot3.Name = "btnNot3";
112             this.btnNot3.Size = new System.Drawing.Size(90, 35);
113             this.btnNot3.TabIndex = 18;
114             this.btnNot3.Text = "3組合";
115             this.btnNot3.UseVisualStyleBackColor = true;
116             this.btnNot3.Click += new System.EventHandler(this.btnNot3_Click);
117             // 
118             // btnNot2
119             // 
120             this.btnNot2.Location = new System.Drawing.Point(71, 59);
121             this.btnNot2.Name = "btnNot2";
122             this.btnNot2.Size = new System.Drawing.Size(90, 35);
123             this.btnNot2.TabIndex = 17;
124             this.btnNot2.Text = "2組合";
125             this.btnNot2.UseVisualStyleBackColor = true;
126             this.btnNot2.Click += new System.EventHandler(this.btnNot2_Click);
127             // 
128             // txtnot
129             // 
130             this.txtnot.Location = new System.Drawing.Point(85, 27);
131             this.txtnot.Name = "txtnot";
132             this.txtnot.Size = new System.Drawing.Size(239, 21);
133             this.txtnot.TabIndex = 16;
134             this.txtnot.Text = "abc012";
135             // 
136             // groupBox2
137             // 
138             this.groupBox2.Controls.Add(this.label4);
139             this.groupBox2.Controls.Add(this.btnNot3);
140             this.groupBox2.Controls.Add(this.btnNot2);
141             this.groupBox2.Controls.Add(this.txtnot);
142             this.groupBox2.Location = new System.Drawing.Point(22, 32);
143             this.groupBox2.Name = "groupBox2";
144             this.groupBox2.Size = new System.Drawing.Size(369, 131);
145             this.groupBox2.TabIndex = 19;
146             this.groupBox2.TabStop = false;
147             this.groupBox2.Text = "取不重覆組合";
148             // 
149             // groupBox1
150             // 
151             this.groupBox1.Controls.Add(this.groupBox2);
152             this.groupBox1.Controls.Add(this.groupBox3);
153             this.groupBox1.Location = new System.Drawing.Point(291, 39);
154             this.groupBox1.Name = "groupBox1";
155             this.groupBox1.Size = new System.Drawing.Size(416, 364);
156             this.groupBox1.TabIndex = 16;
157             this.groupBox1.TabStop = false;
158             this.groupBox1.Text = "操作";
159             // 
160             // label3
161             // 
162             this.label3.AutoSize = true;
163             this.label3.Location = new System.Drawing.Point(155, 11);
164             this.label3.Name = "label3";
165             this.label3.Size = new System.Drawing.Size(41, 12);
166             this.label3.TabIndex = 15;
167             this.label3.Text = "總數:";
168             // 
169             // label1
170             // 
171             this.label1.AutoSize = true;
172             this.label1.Location = new System.Drawing.Point(24, 11);
173             this.label1.Name = "label1";
174             this.label1.Size = new System.Drawing.Size(65, 12);
175             this.label1.TabIndex = 14;
176             this.label1.Text = "顯示結果:";
177             // 
178             // txtShow
179             // 
180             this.txtShow.Location = new System.Drawing.Point(26, 39);
181             this.txtShow.Multiline = true;
182             this.txtShow.Name = "txtShow";
183             this.txtShow.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
184             this.txtShow.Size = new System.Drawing.Size(217, 364);
185             this.txtShow.TabIndex = 12;
186             // 
187             // lbCount
188             // 
189             this.lbCount.AutoSize = true;
190             this.lbCount.Location = new System.Drawing.Point(202, 11);
191             this.lbCount.Name = "lbCount";
192             this.lbCount.Size = new System.Drawing.Size(41, 12);
193             this.lbCount.TabIndex = 13;
194             this.lbCount.Text = "label2";
195             // 
196             // FrmDemo
197             // 
198             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
199             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
200             this.ClientSize = new System.Drawing.Size(724, 414);
201             this.Controls.Add(this.groupBox1);
202             this.Controls.Add(this.label3);
203             this.Controls.Add(this.label1);
204             this.Controls.Add(this.txtShow);
205             this.Controls.Add(this.lbCount);
206             this.Name = "FrmDemo";
207             this.Text = "凹凸組合測試";
208             this.Load += new System.EventHandler(this.FrmDemo_Load);
209             this.groupBox3.ResumeLayout(false);
210             this.groupBox3.PerformLayout();
211             this.groupBox2.ResumeLayout(false);
212             this.groupBox2.PerformLayout();
213             this.groupBox1.ResumeLayout(false);
214             this.ResumeLayout(false);
215             this.PerformLayout();
216 
217         }
218 
219         #endregion
220 
221         private System.Windows.Forms.Label label5;
222         private System.Windows.Forms.Button btnAll2;
223         private System.Windows.Forms.Button btnAll3;
224         private System.Windows.Forms.GroupBox groupBox3;
225         private System.Windows.Forms.TextBox txtAll;
226         private System.Windows.Forms.Label label4;
227         private System.Windows.Forms.Button btnNot3;
228         private System.Windows.Forms.Button btnNot2;
229         private System.Windows.Forms.TextBox txtnot;
230         private System.Windows.Forms.GroupBox groupBox2;
231         private System.Windows.Forms.GroupBox groupBox1;
232         private System.Windows.Forms.Label label3;
233         private System.Windows.Forms.Label label1;
234         private System.Windows.Forms.TextBox txtShow;
235         private System.Windows.Forms.Label lbCount;
236     }
摺疊展開

 

     2.添加引用

         在項目中,添加引用——>AoTu.ZhuHe.dll

     3.窗體類代碼

        

  1 public partial class FrmDemo : Form
  2     {
  3         public FrmDemo()
  4         {
  5             InitializeComponent();
  6         }
  7 
  8         private void FrmDemo_Load(object sender, EventArgs e)
  9         {
 10             string svn = "0b1de737-cea695ab-fc505423-bdd5f3db ";
 11             bool ret = ZhuHeNum.Initia(svn);
 12             if (!ret)
 13                 MessageBox.Show("註冊失敗!");
 14         }
 15 
 16         private void btnNot2_Click(object sender, EventArgs e)
 17         {
 18             string str = txtnot.Text;
 19             List<string> list = ZhuHeNum.NumNoRepeAssembly(str, 2);
 20             if (list == null)
 21             {
 22                 MessageBox.Show("註冊失敗!");
 23                 return;
 24             }
 25             list.Sort();
 26             StringBuilder sbBuilder = new StringBuilder();
 27 
 28             foreach (string s in list)
 29 
              
您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 上一章中筆者講到關於Linq和EF的用法。並以hibernate來進行講解。那麼本章筆者來講一下C#的Asp.Net。即是在B/S模式下開發。現在企業大部分的業務都是面向B/S模式的。所以對於Asp.Net的瞭解變得必不可少的知識點。筆者在從事JAVA開發的時候,很少看到有關於Awt和Swing開發 ...
  • 目錄索引 【無私分享:ASP.NET CORE 項目實戰】目錄索引 簡介 很長時間沒有來更新博客了,一是,最近有些忙,二是,Core也是一直在摸索中,其實已經完成了一個框架了,並且正在準備在生產環境中試用,但是很多東西也是出於自己理解的膚淺和技術的不斷更新,經常變動,所以,如果自己還沒有完全搞好,就 ...
  • 不要急,源代碼分享在最底部,先問大家一個問題,你在寫開放的API介面時是如何保證數據的安全性的?先來看看有哪些安全性問題在開放的api介面中,我們通過http Post或者Get方式請求伺服器的時候,會面臨著許多的安全性問題,例如: 1. 請求來源(身份)是否合法? 2. 請求參數被篡改? 3. 請... ...
  • 一、概念 Moq是利用諸如Linq表達式樹和Lambda表達式等·NET 3.5的特性,為·NET設計和開發的Mocking庫。Mock字面意思即模擬,模擬對象的行為已達到欺騙目標(待測試對象)的效果. Moq模擬類類型時,不可模擬密封類,不可模擬靜態方法(適配器可解決),被模擬的方法及屬性必須被v ...
  • 在編寫開發框架的時候,經常會遇到要找出應用所用到的所有程式集和類,然後進行下一步的處理。 例如,我們有一個通用控制項類BaseControl,各種富文本編輯器控制項、表格控制項、分頁控制項等都繼承於通用控制項類BaseControl。甚至CMS這個項目的評論等控制項也會繼承該通用控制項類BaseControl。我 ...
  • startup startup asp.net core 的入口,在構造函數中完成環境參數的配置。 public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory ...
  • 在很多情況下,我們開發都需要有一個快速的代碼生成工具用來提高開發效率,代碼生成工具很多信息都是讀取資料庫的表、視圖等元數據進行對象表信息的完善,有了這些信息,我們就可以在普通的實體類代碼裡面添加屬性欄位的中文註釋,或者在Winform或者Web界面的快速生成的時候,可以在查詢框或者界面編輯的時候,充... ...
  • 目前.Net Core上沒有System.Drawing這個類庫,想要在.Net Core上處理圖片得另闢蹊徑。 微軟給出了將來取代System.Drawing的方案,偏向於使用一個單獨的服務端進行各種圖片處理 "https://github.com/dotnet/corefx/issues/202 ...
一周排行
    -Advertisement-
    Play Games
  • 示例項目結構 在 Visual Studio 中創建一個 WinForms 應用程式後,項目結構如下所示: MyWinFormsApp/ │ ├───Properties/ │ └───Settings.settings │ ├───bin/ │ ├───Debug/ │ └───Release/ ...
  • [STAThread] 特性用於需要與 COM 組件交互的應用程式,尤其是依賴單線程模型(如 Windows Forms 應用程式)的組件。在 STA 模式下,線程擁有自己的消息迴圈,這對於處理用戶界面和某些 COM 組件是必要的。 [STAThread] static void Main(stri ...
  • 在WinForm中使用全局異常捕獲處理 在WinForm應用程式中,全局異常捕獲是確保程式穩定性的關鍵。通過在Program類的Main方法中設置全局異常處理,可以有效地捕獲並處理未預見的異常,從而避免程式崩潰。 註冊全局異常事件 [STAThread] static void Main() { / ...
  • 前言 給大家推薦一款開源的 Winform 控制項庫,可以幫助我們開發更加美觀、漂亮的 WinForm 界面。 項目介紹 SunnyUI.NET 是一個基於 .NET Framework 4.0+、.NET 6、.NET 7 和 .NET 8 的 WinForm 開源控制項庫,同時也提供了工具類庫、擴展 ...
  • 說明 該文章是屬於OverallAuth2.0系列文章,每周更新一篇該系列文章(從0到1完成系統開發)。 該系統文章,我會儘量說的非常詳細,做到不管新手、老手都能看懂。 說明:OverallAuth2.0 是一個簡單、易懂、功能強大的許可權+可視化流程管理系統。 有興趣的朋友,請關註我吧(*^▽^*) ...
  • 一、下載安裝 1.下載git 必須先下載並安裝git,再TortoiseGit下載安裝 git安裝參考教程:https://blog.csdn.net/mukes/article/details/115693833 2.TortoiseGit下載與安裝 TortoiseGit,Git客戶端,32/6 ...
  • 前言 在項目開發過程中,理解數據結構和演算法如同掌握蓋房子的秘訣。演算法不僅能幫助我們編寫高效、優質的代碼,還能解決項目中遇到的各種難題。 給大家推薦一個支持C#的開源免費、新手友好的數據結構與演算法入門教程:Hello演算法。 項目介紹 《Hello Algo》是一本開源免費、新手友好的數據結構與演算法入門 ...
  • 1.生成單個Proto.bat內容 @rem Copyright 2016, Google Inc. @rem All rights reserved. @rem @rem Redistribution and use in source and binary forms, with or with ...
  • 一:背景 1. 講故事 前段時間有位朋友找到我,說他的窗體程式在客戶這邊出現了卡死,讓我幫忙看下怎麼回事?dump也生成了,既然有dump了那就上 windbg 分析吧。 二:WinDbg 分析 1. 為什麼會卡死 窗體程式的卡死,入口門檻很低,後續往下分析就不一定了,不管怎麼說先用 !clrsta ...
  • 前言 人工智慧時代,人臉識別技術已成為安全驗證、身份識別和用戶交互的關鍵工具。 給大家推薦一款.NET 開源提供了強大的人臉識別 API,工具不僅易於集成,還具備高效處理能力。 本文將介紹一款如何利用這些API,為我們的項目添加智能識別的亮點。 項目介紹 GitHub 上擁有 1.2k 星標的 C# ...