51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

123
返回列表 发新帖
楼主: walker1020
打印 上一主题 下一主题

[原创] 编程练习题

[复制链接]

该用户从未签到

41#
发表于 2009-8-21 13:03:09 | 只看该作者

回复 35# 的帖子

We shall say that an n-digit number is pandigital if it makes use of all the digits 1 to n exactly once. For example, 2143 is a 4-digit pandigital and is also prime.

What is the largest n-digit pandigital prime that exists?
回复 支持 反对

使用道具 举报

该用户从未签到

42#
发表于 2009-8-21 13:09:14 | 只看该作者
我来贴点稍微有些难度的题吧,前阵子我刚做过的
http://projecteuler.net/index.php?section=problems&id=191

无论用什么方法,只要能计算出结果就可以了,当然,我自己是用VBS做出来的
回复 支持 反对

使用道具 举报

该用户从未签到

43#
发表于 2009-8-27 14:08:30 | 只看该作者

回复 1# 的帖子

前几天看到php里有1个addcslashes()函数,所以用vbs山寨了1个,应该可以满足第1题里的要求吧。
PS:题目我没看太明白,呵呵。
--------------------------------------------------------------------------------------------------
'array_unique(arr)用来去除数组中的重复项,该函数使用了dictionary中key不能使用重复项的特性,有些危险.....慎用.....
Function array_unique(arr)
        size = UBound(arr) + 1
        Dim hash
        Set hash = CreateObject("scripting.dictionary")
        Dim count
        count = 0
        For i = 0 To (size - 1)
                On Error Resume Next
                key = arr(i)               
                For Each value In arr
                        If arr(i) = value Then
                                count = count + 1
                        End If
                Next               
                        hash.Add key , count
                        count = 0               
                Next       
        array_unique = hash.Keys
        Set hash = nothing
End Function
-----------------------------------邪恶的分隔线-----------------------------------------------------------
'addcslashes(str, charlist)从str中找到charlist中指定的字符并在前面添加"\",charlist支持正则表达式,因此如果是找正则表达式中的特殊字符的话,只需要这样写charlist[|\^*.\\]之类的,具体的大家可以用正则来写一下。另外目前该函数只支持单字符搜索,有其他需求的兄弟可以自行修改一下。
Function addcslashes(str, charlist)
        Set reg = New RegExp
        reg.IgnoreCase = False
        'If InStr(str,"^") Then
        '        str = Replace(str, "^", "\^")
        'End If
        reg.Pattern = charlist       
        reg.Global = false
        Set hash = CreateObject("scripting.dictionary")
        i = 0
        Set matches = reg.Execute(str)       
        For Each match In matches
                pos = match.FirstIndex + 1
                hash.Add i, Mid(str, pos, 1)
                i = i + 1
        Next
        newArr = array_unique(hash.Items)
        For Each value In newArr
                str = Replace(str, value, ("\" & value))
        Next
        addcslashes = str       
        set hash = nothing
End Function
回复 支持 反对

使用道具 举报

本版积分规则

关闭

站长推荐上一条 /1 下一条

小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

GMT+8, 2024-5-2 16:31 , Processed in 0.062184 second(s), 21 queries .

Powered by Discuz! X3.2

© 2001-2024 Comsenz Inc.

快速回复 返回顶部 返回列表