私は、C# Vs 2010 で SCRATCH カード コード ジェネレーターのプログラムを作成しています。可能な数の組み合わせと一意の番号を生成し、番号が繰り返されないことを意味します。
例えば:
5!= 120 の組み合わせまたは可能な数字
2!= 2 つの組み合わせまたは可能な数字
整数値と文字列値を同時に与えることができ、プログラムが正常に実行されている可能な組み合わせを生成します..
MAIN METHOD string c = "abc"; に新しい値を設定できます。
例: (ここで値を変更できます) string c = "abc"; 文字列 c = "1232abc";
THEコード全体はコンソール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 FORM C# で変換できないことです CONSOLE で行っていた一意の番号が生成されません WINDOWS FORM で実行しようとしたプログラム 検出できない問題は何ですか
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;
}
CONSOLE PROGRAMで発生しているように、UNIQUE番号を生成しないのはなぜですか??? 何が問題ですか????