利用正则判别素数,来源于网络,神人!
复制代码 代码如下:
复制代码
Set regex = New RegExp
regex.Pattern = "^1?$¦^(11+?)\1+$"
For i = 1 To 100
If Not regex.Test(String(i,"1")) Then
WScript.Echo i
End If
Next
Set regex = New RegExp
regex.Pattern = "^1?$¦^(11+?)\1+$"
For i = 1 To 100
If Not regex.Test(String(i,"1")) Then
WScript.Echo i
End If
Next
看到标题你一定会不屑一顾,枚举质数谁不会?
复制代码 代码如下:
复制代码
For i = 1 To 100
For j = 2 To i
If i Mod j = 0 Then Exit For
Next
If j = i Then WScript.Echo i
Next
For i = 1 To 100
For j = 2 To i
If i Mod j = 0 Then Exit For
Next
If j = i Then WScript.Echo i
Next
几行代码就能搞定,如此简单。那就看看下面这个程序吧!
复制代码 代码如下:
复制代码
Set regex = New RegExp
regex.Pattern = "^1?$|^(11+?)\1+$"
For i = 1 To 100
If Not regex.Test(String(i,"1")) Then
WScript.Echo i
End If
Next
Set regex = New RegExp
regex.Pattern = "^1?$|^(11+?)\1+$"
For i = 1 To 100
If Not regex.Test(String(i,"1")) Then
WScript.Echo i
End If
Next
用正则表达式判断质数,神一样的人物。
来源:
http://demon.tw/programming/vbs-prime-number.html
http://www.enun.net/?p=533
最后
以上就是纯真摩托最近收集整理的关于VBS 正则判别素数(质数)的全部内容,更多相关VBS内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复