
正文
包含VB.NET实现数组拼接的词条
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
vb.net变成 数组组合情况输出问题
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication42
{
class Program
{
static void Main(string[] args)
{
count = 0;
String[] s = Console.ReadLine().Split(' ');
int[] array = new int[s.Length];
for (int i = 0; i s.Length; i++)
{
array[i] = Convert.ToInt32(s[i]);
}
int m = Convert.ToInt32(Console.ReadLine());
Listint arraylist = new Listint();
arraylist.AddRange(array);
Output(arraylist, m, null);
Console.WriteLine("共有" + count.ToString() + "个");
Console.ReadKey();
}
static int count = 0;
static void Output(Listint array, int m, Listint output)
{
if (output == null)
output = new Listint();
if (m == 0)
{
for (int i = 0; i output.Count; i++)
{
Console.Write(output[i].ToString() + " ");
}
Console.Write("\r\n");
count++;
return;
}
else
{
for (int i = 0; i array.Count; i++)
{
Listint output2 = new Listint();
output2.AddRange(output.ToArray());
output.Add(array[i]);
Listint array2 = new Listint();
array2.AddRange(array.ToArray());
for (int j = 0; j = i; j++)
{
int number = array[j];
array2.Remove(number);
}
Output(array2, m - 1, output);
output.Clear();
output.AddRange(output2.ToArray());
}
}
}
}
}
额VB.NET实现数组拼接,没注意VB,用C#写VB.NET实现数组拼接的。。。
输出了的,你新建一个C#控制台程序,把这段贴进去,运行一下就知道了
先输入一组字符串,然后输入一个整数,就会把所有的组合输出出来
VB.NET实现数组拼接我把这段转成VB再发一次吧
Module Module1
Sub Main()
count = 0
Dim s As String() = Console.ReadLine().Split(" ")
Dim array(0 To s.Length - 1) As Integer
For i As Integer = 0 To s.Length - 1
array(i) = Convert.ToInt32(s(i))
Next
Dim m As Integer = Convert.ToInt32(Console.ReadLine())
Dim arraylist As New List(Of Integer)
arraylist.AddRange(array)
Print(arraylist, m, Nothing)
Console.WriteLine("共有" + count.ToString() + "个")
Console.ReadKey()
End Sub
Sub Print(ByRef array As List(Of Integer), ByVal m As Integer, ByRef output As List(Of Integer))
If output Is Nothing Then
output = New List(Of Integer)()
End If
If m = 0 Then
For i As Integer = 0 To output.Count - 1
Console.Write(output(i).ToString() + " ")
Next
Console.Write(vbCrLf)
count = count + 1
Return
Else
For i As Integer = 0 To array.Count - 1
Dim array2 As New List(Of Integer)
Dim output2 As New List(Of Integer)
output2.AddRange(output.ToArray())
output.Add(array(i))
array2.AddRange(array.ToArray())
For j As Integer = 0 To i
Dim number As Integer = array(j)
array2.Remove(number)
Next
Print(array2, m - 1, output)
output.Clear()
output.AddRange(output2.ToArray())
Next
End If
End Sub
Dim count As Integer = 0
End Module
相关问答
Q1: VB 怎样加将两个数组合并
Private Sub Command1_Click()
a = Array(1, 2, 4, 7, 9, 34, 65, 73, 78, 99, 234, 1234)
b = Array(0, 23, 33, 56, 78, 98, 99, 234, 1000, 9999)
Dim c(30)
i = 0
j = 0
k = 0
While i = UBound(a) And j = UBound(b)
If a(i) b(j) Then
c(k) = a(i)
i = i + 1
Else
c(k) = b(j)
j = j + 1
End If
k = k + 1
Wend
While i UBound(a)
c(k) = a(i)
i = i + 1: k = k + 1
Wend
While j UBound(b)
c(k) = b(j)
j = j + 1: k = k + 1
Wend
Print "原A数组VB.NET实现数组拼接:"
For i = 0 To UBound(a)
Print a(i);
Next i
Print "原B数组VB.NET实现数组拼接:"
For i = 0 To UBound(b)
Print b(i);
Next i
Print "合并后VB.NET实现数组拼接的c数组VB.NET实现数组拼接:"
For i = 0 To k
Print c(i);
If i Mod 15 = 14 Then Print
Next i
End Sub
Q2: vb.net 两个数组拼接添加进listbox,结果只添加了第一个数组,第二个数组丢失了,这是怎么回事,在线等答案
S_chflag1(n) = Zonename(str_qy) ":" Chname1(str_xd)
字符串拼接尽量不用加号
Q3: VB怎么把两个数组合并
1. VB 怎样加将两个数组合并
你的问题 首先没有定义全局变量,
你开始说你要把数组1,2合并到1里不是多此一举,,开始全部写到1里不就完了,
后来好了 把数组1,2 合并到另一个数组,,这个是可行的,,
越界,,,加了个全局变量就可以了,,
代码在下面,,测试可行
Dim shuzu2(), shuzu1(), m, n As Double
Private Sub mand1_Click()
n = InputBox("", "输入数组1个数")
ReDim shuzu1(1 To n)
For I = 1 To Val(n)
A = InputBox("", "请输入数字")
shuzu1(I) = A
Text2 = Text2 shuzu1(I) ","
Next I
'数组2的输入
m = InputBox("", "输入数组2个数")
ReDim shuzu2(1 To m)
For I = 1 To Val(m)
A = InputBox("", "请输入数字")
shuzu2(I) = A
Text1 = Text1 shuzu2(I) ","
Next I
End Sub
'将数组2合并到数组1
Private Sub mand3_Click()
ReDim HEBING(1 To m + n) As Integer
For I = 1 To n
HEBING(I) = shuzu1(I)
Text3 = Text3 HEBING(I)
Next I
For I = n + 1 To m + n
HEBING(I) = shuzu2(I - n) '在这里总说下标越界。
Text3 = Text3 HEBING(I)
Next I
End Sub
2. VB 怎样加将两个数组合并
Private Sub mand1_Click() a = Array(1, 2, 4, 7, 9, 34, 65, 73, 78, 99, 234, 1234) b = Array(0, 23, 33, 56, 78, 98, 99, 234, 1000, 9999) Dim c(30) i = 0 j = 0 k = 0 While i = UBound(a) And j = UBound(b) If a(i) b(j) Then c(k) = a(i) i = i + 1 Else c(k) = b(j) j = j + 1 End If k = k + 1 Wend While i UBound(a) c(k) = a(i) i = i + 1: k = k + 1 Wend While j UBound(b) c(k) = b(j) j = j + 1: k = k + 1 Wend Print "原A数组e79fa5e98193e58685e5aeb931333337623437:" For i = 0 To UBound(a) Print a(i); Next i Print Print "原B数组:" For i = 0 To UBound(b) Print b(i); Next i Print Print "合并后的c数组:" For i = 0 To k Print c(i); If i Mod 15 = 14 Then Print Next i Print End Sub 。
3. 怎样把两个数组合并为一个
Private Sub mand1_Click()
Dim a(1 To 10), b(1 To 10), c(1 To 20)
Randomize
For i = 1 To 10
a(i) = Int(Rnd * 100)
b(i) = Int(Rnd * 100)
Next i
For i = 1 To 9
For j = 10 To i + 1 Step -1
If a(i) a(j) Then d = a(i): a(i) = a(j): a(j) = d
If b(i) b(j) Then d = b(i): b(i) = b(j): b(j) = d
Next j, i
For i = 1 To 10
Print a(i);
Next i
For i = 1 To 10
Print b(i);
Next i
'下面就是合并过程
j = 1
For i = 1 To 10
Do
If a(i) k = k + 1
c(k) = a(i)
Exit Do
Else
k = k + 1
c(k) = b(j)
j = j + 1
If j 10 Then Exit For
End If
Loop
Next i
If i For n = i To 10
k = k + 1
c(k) = a(n)
Next n
End If
If j For n = j To 10
k = k + 1
c(k) = b(n)
Next n
End If
'合并结束
For i = 1 To 20
Print c(i);
Next i
End Sub
Private Sub Form_Load()
Me.AutoRedraw = True
End Sub
4. 怎么两个数组合并一组数,由大到小排列 vb
定义第三个数组,先把其中一个数组写到第三个中,再把第二个数组添加到第三个尾部,再对第三个数组排序。
如:
Private Sub mand3_Click()
Dim a(1 To 5), b(1 To 6), c(1 To 11), i, j As Integer
For i = 1 To 5
a(i) = i
Print a(i);
Next
For i = 1 To 6
b(i) = i + 6
Print b(i);
Next
For i = 1 To 5
c(i) = a(i)
Next
For i = 1 To 6
c(i + 5) = b(i)
Next
For i = 1 To 11
Print c(i);
Next
End Sub
5. 用vb实现两个数相加的问题
Private Sub mand3_Click()
Text1.Text = mand1.Caption mand3.Caption mand2.Caption "="
End Sub
Private Sub mand4_Click()
Text1.Text = mand1.Caption mand3.Caption mand2.Caption "=" CStr(Val(mand1.Caption) + Val(mand2.Caption))
End Sub
Private Sub Form_Load()
mand1.Caption = "1"
mand2.Caption = "2"
mand3.Caption = "+"
mand4.Caption = "="
End Sub
Q4: 求大神指点 vb.net 怎么把 几个字节集 连接起来呢? 我用 +和 & 都报错
Dim a As Byte() = New Byte() {1, 2, 3, 4}
Dim b As Byte() = New Byte() {5, 6, 7, 8}
Dim c As Byte() = a.Concat(b).ToArray
'c={1,2,3,4,5,6,7,8}
VB.NET实现数组拼接的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于、VB.NET实现数组拼接的信息别忘了在本站进行查找喔。






