资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

vb.net常用算法,vb函数运算

VB.NET数组的排序法?

如果你是从vb6刚过渡上vb。net,建议还是用冒泡排序法,容易理解。

为朝阳县等地区用户提供了全套网页设计制作服务,及朝阳县网站建设行业解决方案。主营业务为网站建设、成都网站制作、朝阳县网站设计,以传统方式定制建设网站,并提供域名空间备案等一条龙服务,秉承以专业、用心的态度为用户提供真诚的服务。我们深信只要达到每一位用户的要求,就会得到认可,从而选择与我们长期合作。这样,我们也可以走得更远!

如果你正努力学习vb。net的方法,推荐一个例子如下:

Imports System

Imports System.Collections

Public Class SamplesArray

Public Class myReverserClass

Implements IComparer

' Calls CaseInsensitiveComparer.Compare with the parameters reversed.

Function Compare(x As Object, y As Object) As Integer _

Implements IComparer.Compare

Return New CaseInsensitiveComparer().Compare(y, x)

End Function 'IComparer.Compare

End Class 'myReverserClass

Public Shared Sub Main()

' Creates and initializes a new Array and a new custom comparer.

Dim myArr As [String]() = {"The", "QUICK", "BROWN", "FOX", "jumps", "over", "the", "lazy", "dog"}

Dim myComparer = New myReverserClass()

' Displays the values of the Array.

Console.WriteLine("The Array initially contains the following values:")

PrintIndexAndValues(myArr)

' Sorts a section of the Array using the default comparer.

Array.Sort(myArr, 1, 3)

Console.WriteLine("After sorting a section of the Array using the default comparer:")

PrintIndexAndValues(myArr)

' Sorts a section of the Array using the reverse case-insensitive comparer.

Array.Sort(myArr, 1, 3, myComparer)

Console.WriteLine("After sorting a section of the Array using the reverse case-insensitive comparer:")

PrintIndexAndValues(myArr)

' Sorts the entire Array using the default comparer.

Array.Sort(myArr)

Console.WriteLine("After sorting the entire Array using the default comparer:")

PrintIndexAndValues(myArr)

' Sorts the entire Array using the reverse case-insensitive comparer.

Array.Sort(myArr, myComparer)

Console.WriteLine("After sorting the entire Array using the reverse case-insensitive comparer:")

PrintIndexAndValues(myArr)

End Sub 'Main

Public Shared Sub PrintIndexAndValues(myArr() As [String])

Dim i As Integer

For i = 0 To myArr.Length - 1

Console.WriteLine(" [{0}] : {1}", i, myArr(i))

Next i

Console.WriteLine()

End Sub 'PrintIndexAndValues

End Class 'SamplesArray

'This code produces the following output.

'

'The Array initially contains the following values:

' [0] : The

' [1] : QUICK

' [2] : BROWN

' [3] : FOX

' [4] : jumps

' [5] : over

' [6] : the

' [7] : lazy

' [8] : dog

'

'After sorting a section of the Array using the default comparer:

' [0] : The

' [1] : BROWN

' [2] : FOX

' [3] : QUICK

' [4] : jumps

' [5] : over

' [6] : the

' [7] : lazy

' [8] : dog

'

'After sorting a section of the Array using the reverse case-insensitive comparer:

' [0] : The

' [1] : QUICK

' [2] : FOX

' [3] : BROWN

' [4] : jumps

' [5] : over

' [6] : the

' [7] : lazy

' [8] : dog

'

'After sorting the entire Array using the default comparer:

' [0] : BROWN

' [1] : dog

' [2] : FOX

' [3] : jumps

' [4] : lazy

' [5] : over

' [6] : QUICK

' [7] : the

' [8] : The

'

'After sorting the entire Array using the reverse case-insensitive comparer:

' [0] : the

' [1] : The

' [2] : QUICK

' [3] : over

' [4] : lazy

' [5] : jumps

' [6] : FOX

' [7] : dog

' [8] : BROWN

vb.net 排列组合算法

看了你说递归的效率低。那么你可以不用的。

给出的方法就是先生成第一个排列,然后每次调用下面的函数给出下一个排列,这样生成的效率很高,这个函数可以内联。

这个是很经典的排列组合算法啊?在网上能搜到一大堆。

大概是那种带指向的移动的算法。我给你搜一个吧。

我找了几个,这个是我觉得说的比较清楚的,你可以仔细参考一下,看不懂的话再搜点别的好了。。

全排列的算法跟这个不太一样的。需要有点改动的。

至于语言的话,应该不会有太大问题吧。。basic版的确实比较少,现在我也比较懒不想动手写。。还是要靠你自己啦。

★生成排列的算法:

比如要生成5,4,3,2,1的全排列,首先找出一个最小的排列12345, 然后依次调用n!次STL算法中的next_permutation()即可输出所有的全排列情况。所以这种算法的细节就是STL algorithm中next_permutation()的实现机制。详细的实现代码,大伙可以参考侯捷的《STL源代码剖析》,在这里我只说一下我的理解:

1 首先从最尾端开始往前寻找两个相邻元素,令第一个元素为*i,第二个元素为*ii,且满足*i*ii,找到这样一组相邻的元素后。

2 再从最尾端开始往前检验,找出第一个大于*i的元素,令为*k,将i,k元素对调。

3 再将ii及ii之后的所有元素颠倒排列,此即所求之"下一个"排列。

prev_permutation()算法的思路也基本相同,只不过它们寻找的"拐点"不同,在next_permutation()算法中寻找的是峰值拐点,而在prev_permutation()算法中寻找的是谷值拐点。另外,在第二步中,prev_permutation()要找的是第一个小于*i的元素而不是第一个大于*i的元素。

具体例子,有空再举,现在时间太晚了:)

★生成组合的算法:

如下面截图所示,分全组合和r-组合两种情况。

这里有一段核心代码:

//--------------------------------------------------------

// Generate next combination (algorithm from Rosen p. 286)

//--------------------------------------------------------

public int[] getNext () {

if (numLeft.equals (total)) {

numLeft = numLeft.subtract (BigInteger.ONE);

return a;

}

int i = r - 1;

while (a[i] == n - r + i) {

i--;

}

a[i] = a[i] + 1;

for (int j = i + 1; j r; j++) {

a[j] = a[i] + j - i;

}

numLeft = numLeft.subtract (BigInteger.ONE);

return a; //这里返回的a数组,存储的就是下标的排列组合。

}

到这里,也许大伙会有一个疑问,假如要求的不是数字的排列组合,而是字符或字符串的排列组合呢?怎么办?其实很简单,你只要拿数组的下标来做排列组合,返回他们下标的排列组合,然后再到原数组中读取字符串值,就可以输出全部的排列组合结果。

加密解密高手进!VB.NET 谁能给一个MD5或其他的加密算法

注意参数,Text是密文。sKey是你的加密干扰符

Public Shared Function Decrypt(ByVal Text As String, ByVal sKey As String) As String

Dim provider As New DESCryptoServiceProvider()

Dim num As Integer = Text.Length \ 2

Dim buffer As Byte() = New Byte(num - 1) {}

For i As Integer = 0 To num - 1

Dim num3 As Integer = Convert.ToInt32(Text.Substring(i * 2, 2), H10)

buffer(i) = CByte(num3)

Next

provider.Key = Encoding.ASCII.GetBytes(FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8))

provider.IV = Encoding.ASCII.GetBytes(FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8))

Dim stream As New MemoryStream()

Dim stream2 As New CryptoStream(stream, provider.CreateDecryptor(), CryptoStreamMode.Write)

stream2.Write(buffer, 0, buffer.Length)

stream2.FlushFinalBlock()

Return Encoding.[Default].GetString(stream.ToArray())

End Function

求vb.net的哈希加密算法的代码?

病情分析:

你好!

你怀孕31周,已经属于孕晚期了,这个时期,胎动频繁是比较正常的现象。如果怀孕月份再大一些,胎动就不会这么明显了。你的宝宝动得很利害,这与你的往哪边睡没有特别大的关系的。正好相反,你往左侧睡时,胎盘血液循环较好,胎儿感觉比较舒服,才会在子宫内活动。

指导意见:

在怀孕晚期,原则上应该多往左侧睡,以利于胎盘的血液循环,对于胎儿有利。但是,如果你感觉左侧睡胎动明显,那么,也可以换到右侧睡或是平躺着睡,只要睡得舒服,怎么睡都可以的,并不要强求往哪一侧睡。

建议你放松心情,平时可以自测胎动的,如果每小时大约3--5次,则为正常现象。如果感觉异常,还可以到医院做胎心音监测的。

祝你健康!

病情分析:

根据你说的情况,现在胎儿的反应是正常的,没有看出什么异常

指导意见:

胎儿每天也要适当的活动的,所以你不要担心,定期到医院进行孕检就可以了

病情分析:

现在怀孕31周,左侧睡是宝宝动的厉害,说明宝宝对于你这个姿势很不舒服!

指导意见:

左侧睡觉也会压迫心脏的,所以你应该选择右侧睡觉的,以宝宝最舒服的姿势来睡觉!

VB.NET的阳历与农历转换的算法

根据经验, 这个算法非常复杂. 经过查找,终于得到一些资料, 在此愿与大家分享。 首先阴历以月为基本单位,一个月以新月出现的那一天为始直至下一个新月出现的前一天。 由于月亮公转的周期介于29到30天之间,阴历的一个月也就由新月出现时刻的早晚或是29天或是30天。 大月为30天,小月为29天。 与阳历不同的是,大小月在不同的年中不固定。 如春节的前一天常称为大年三十,但有不少年如2000年的阴历十二月只有29天。 由于十二个月的时间较阳历年即地球绕太阳公转一周的时间短11天左右. 为了使阴历年与阳历年保持相对稳定,每隔两三年就需要加入一个闰月。 大约每十九年要加入七个闰月。 而二十四节气则是由地球在绕太阳公转的轨道上的位置确定的。 以每年的冬至为始,每15度为一个节气。 是故二十四节气在阳历的每月中有大概固定的日期。 古时以二十四节气指导农耕,这就是阴历又称农历的原因。 其中阳历下半月的十二个节气又称为中气。 中气出现的时刻和闰月的确定有直接的关系。 阴历的计算有下列四条规则: 1.所有新月和节气出现的时刻的计算以东经120度即东八区标准时为准。 但计算1929年以前的阴历时应以北京即东经116度25分的当地时为准。 2.新月出现的一天为一个月的第一天。 如某个节气的出现时刻也在这一天,则不论该节气的出现时刻是否比新月晚,一律算落入新的一个月中。 3.每年的冬至总是落在这年的十一月中。 从一年的冬至的第二天起到下一年冬至这一天止的这段时间称为一岁。 如一岁中有十三个新月出现,则这一岁为闰岁,要加入一个闰月。 4.闰岁中第一个没有中气的月为闰月。 因为一岁中只有十二个中气,所以闰岁中至少有一个月没有中气,也存在有两个月没有中气的可能性。 但这种情况下只有第一个没有中气的月为闰月。 闰月的前一个月为几月则该闰月称为闰几月。 根据以上信息, 我们知道农历是根据天文观测进行指定的(也许可以在天文学的书上找到说明)。 为了简化转换计算, 很多程序人员设计了基于"时间段内查表"方法的例程. 更具体的说明和源码请参考下面这些资料:

求VB.NET的MD5算法调用

下面是完整的类,可以设置任意密码

'DES及md5加密解密----添加引用中添加对system.web的引用。

Imports System.Security.Cryptography

Imports System

Imports System.Text

Imports System.Web

''' summary

''' DES加密类

''' /summary

''' remarks/remarks

Public Class DESEncrypt

Public Sub DESEncrypt()

End Sub

Public Shared Function Encrypt(ByVal Text As String) As String

Return Encrypt(Text, "12345678")

End Function

Public Shared Function Encrypt(ByVal Text As String, ByVal sKey As String) As String

Dim des As New DESCryptoServiceProvider()

Dim inputByteArray As Byte()

inputByteArray = Encoding.Default.GetBytes(Text)

des.Key = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8))

des.IV = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8))

Dim ms As New System.IO.MemoryStream()

Dim cs As New CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write)

cs.Write(inputByteArray, 0, inputByteArray.Length)

cs.FlushFinalBlock()

Dim ret As New StringBuilder()

Dim b As Byte

For Each b In ms.ToArray()

ret.AppendFormat("{0:X2}", b)

Next

Return ret.ToString()

End Function

Public Shared Function Decrypt(ByVal Text As String) As String

Return Decrypt(Text, "12345678")

End Function

Public Shared Function Decrypt(ByVal Text As String, ByVal sKey As String) As String

Dim des As New DESCryptoServiceProvider()

Dim len As Integer

len = Text.Length / 2

Dim inputByteArray(len - 1) As Byte

Dim x, i As Integer

For x = 0 To len - 1

i = Convert.ToInt32(Text.Substring(x * 2, 2), 16)

inputByteArray(x) = CType(i, Byte)

Next

des.Key = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8))

des.IV = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8))

Dim ms As New System.IO.MemoryStream()

Dim cs As New CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write)

cs.Write(inputByteArray, 0, inputByteArray.Length)

cs.FlushFinalBlock()

Return Encoding.Default.GetString(ms.ToArray())

End Function

End Class

'以下是调用方法

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click '加密

Dim str_Encrypt As String = DESEncrypt.Encrypt("你要加密的文本,可以是任意长度", "密码,可以很长,如果省略这个参数就是默认的12345678")

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click '解密

Dim str_Decrypt As String = DESEncrypt.Decrypt("你要解密的文本, 可以是任意长度", "加密时用到的密码,如果省略这个参数就是默认的12345678")

End Sub


文章名称:vb.net常用算法,vb函数运算
链接分享:http://cdkjz.cn/article/dsejsdp.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220