我想提出的刮獎卡代碼生成的程序在C#中的VS 2010 .. 產生組合的可能數量和唯一編號以及 意味着數量不重複需要C#中的刮刮卡代碼生成器的解決方案嗎?
例如:
5! = 120組合或可能的數字
2! = 2的組合或可能的數字
我們可以給整數值,並在同一時間字符串值,並且它產生其可能的組合 程序成功運行..
可以在主要方法串c設置新值= 「ABC」;
例如:(您可以在此更改值) string c =「abc」; string c =「1232abc」;
整個代碼是在這裏控制檯C#: -
static void Main(string[] args)
{
Permute p = new Permute();
// here u can change value in string
string c = "abc";
char[] c2 = c.ToCharArray();
p.setper(c2);
Console.ReadKey();
}
class Permute
{
int count = 0 ;
private void swap (ref char a, ref char b)
{
char x;
if(a==b)return;
x = a;
a = b;
b = x;
}
public void setper(char[] list)
{
int x=list.Length-1;
go(list,0,x);
}
private void go (char[] list, int k, int m)
{
int i;
if (k == m)
{
Console.Write (list);
count++;
Console.WriteLine (" "+ count );
}
else
for (i = k; i <= m; i++)
{
swap (ref list[k],ref list[i]);
go (list, k+1, m);
swap (ref list[k],ref list[i]);
}
}
問題是,我們不能在Windows窗體C# 轉換時,我們把它不會產生這是在控制檯程序中做的唯一編號 我們已經嘗試做它在Windows窗體有什麼問題,我們不能檢測到它
的代碼,Windows窗體C#是(我們都試過):
// this is our Button 1 we have changed name to BtGenerate
// we have used LISTBOX to show the generated values
// or u can say to show numbers in Listbox
private void BtGenerate_Click(object sender, EventArgs e)
{
string abc = textBox1.Text;
char[] c = abc.ToCharArray();
Permutation p = new Permutation();
string value = p.setper(c);
// here is our listbox
listBox1.Items.Add(value);
}
// we have used the PERMUTATION Class here
// which is generating numbers
// this class is changed compared to console Permutation class
class Permutation
{
public string Value;
private void swap(ref char a, ref char b)
{
if (a == b) return;
a ^= b;
b ^= a;
a ^= b;
}
public string setper(char[] list)
{
int x = list.Length - 1;
string ValueInString = go(list, 0, x);
return ValueInString;
}
int x = 0;
private string go(char[] list, int k, int m)
{
int i;
if (k == m)
{
if(x == 0)
{
x++;
for (int j = 0; j < list.Length; j++)
{
Value = Value + list[j].ToString();
}
//this code is used which gives gap like arrow to seperate number
//because we are not able to generate each number to new line
Value = Value + @"<--" + x + " ";
}
if (x > 0)
{
x++;
for (int j = 0; j < list.Length; j++)
{
Value = Value + list[j].ToString();
}
Value = Value + @"<--"+ x + " ";
}
}
else
for (i = k; i <= m; i++)
{
swap(ref list[k], ref list[i]);
go(list, k + 1, m);
swap(ref list[k], ref list[i]);
}
return Value;
}
爲什麼它不生成唯一的數字,因爲它發生在控制檯程序中??? 是什麼問題?
你爲什麼重寫它?這幾乎是肯定的問題。 – Bobson
我立即注意到的一件事是,在你的表單應用程序中,每次你點擊你正在生成一個'Permutation'的新實例。 –
是Matt Burland ..我們正在調用我們的類方法,該數字可能會生成.. – mh51