허접하나마 윈폼으로 한번 만들어 봤습니다.
실행파일을 올릴 줄 몰라서 소스만 붙여 넣었습니다.
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;
using System.Collections;
namespace Lotto
{
public partial class Form1 : Form
{
public int[] nCollect = new int[6];
public Form1()
{
InitializeComponent();
}
private void btn_CreateNum_Click(object sender, EventArgs e)
{
Random rd_Num = new Random();
int[] nBase = new int[46];
int DoCount = 1;
string AllSelNums = "";
try
{
// 1. 수행횟수값 받기
if (this.txtCount.Text != "")
DoCount = Convert.ToInt32(this.txtCount.Text);
// 2. 수행결과값을 문자열로 저장(구분자 ",")
for (int i = 0; i < DoCount; i++)
{
HashSet<int> HS_Num = new HashSet<int>();
while (HS_Num.ToArray<int>().Length < 6)
{
HS_Num.Add(rd_Num.Next(1, 45));
}
nCollect = HS_Num.ToArray<int>();
foreach (int sNum in nCollect)
{
AllSelNums += sNum.ToString() + ",";
}
}
// 3. 수행결과를 배열로 변경(정렬(내림차순)포함)
int[] arrAllSelNum = Array.ConvertAll<string, int>(AllSelNums.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries), int.Parse);
Array.Sort(arrAllSelNum, (item1, item2) => { return Comparer<int>.Default.Compare(item1, item2); });
// 4. 중복값 처리
ArrayList SelNumList = new ArrayList();
ArrayList SelCntList = new ArrayList();
foreach (int intNum in arrAllSelNum)
{
if (SelNumList.Contains(intNum))
{
int point = SelNumList.BinarySearch(intNum);
SelCntList[point] = (int)SelCntList[point] + 1;
}
else
{
SelNumList.Add(Convert.ToInt32(intNum));
SelCntList.Add(1);
}
}
// 5. 최대 중복된 순서로 정렬
for (int i = 0; i < SelCntList.Count; i++)
{
for (int j = i + 1; j < SelCntList.Count; j++)
{
int cntHigh = 0;
int cntLow = 0;
int numHigh = 0;
int numLow = 0;
if ((int)SelCntList[i] < (int)SelCntList[j])
{
cntHigh = (int)SelCntList[j];
cntLow = (int)SelCntList[i];
SelCntList[i] = cntHigh;
SelCntList[j] = cntLow;
numHigh = (int)SelNumList[j];
numLow = (int)SelNumList[i];
SelNumList[i] = numHigh;
SelNumList[j] = numLow;
}
}
}
// 6. 정렬된 값에서 6개 추출하여 출력
nCollect = new int[] { (int)SelNumList[0], (int)SelNumList[1], (int)SelNumList[2], (int)SelNumList[3], (int)SelNumList[4], (int)SelNumList[5] };
Array.Sort(nCollect, (item1, item2) => { return Comparer<int>.Default.Compare(item1, item2); });
for (int i = 1; i <= 6; i++)
{
TextBox numBox = (TextBox)this.FindForm().Controls["txtSelNum" + i.ToString()];
numBox.Text = nCollect[i - 1].ToString();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
}
}
}
}