- 按键认证大神
- 2699998
- 3587
- 11
- 2173 朵
- 7386 个
- 1021 个
- 91120
- 2014-08-23
|
1#
t
T
发表于 2022-04-20 21:05
|
|只看楼主
每日题目 给定一个字符串,请编写一个函数,依次先后统计大写字母、小写字母、数字和特殊字符的个数。
【示例】 输入:*'&ABCDabcde12345 输出:[4,5,5,3] 解释:大写字母有4个(ABCD),小写字母有5个(abcde),数字有5个(12345),特殊字符有3个(*’&)
题目难度:简单 题目来源:CodeWars-Simple string characters 13
|
- Import "SmAssert.dll"
- Function 字串计数(字符串)
- // 您的代码在这里
- End Function
- SmAssert.That 字串计数("*'&ABCDabcde12345") ,"in", Array(4,5,5,3)
- SmAssert.That 字串计数("bgA5<1d-tOwUZTS8yQ") ,"in", Array(7,6,3,2)
- SmAssert.That 字串计数("@mw>0=QD-iAx!rp9TaG?o&M%l$34L.nbft") ,"in", Array(7,13,4,10)
复制代码 参考题解- Import "SmAssert.dll"
- Function 字串计数(字符串)
- '【作者】:神梦无痕
- '【QQ】:1042207232
- '【Q群】:624655641
- Dim Ret(3)
- Dim i, s
-
- For i = 1 To Len(字符串)
- s = Mid(字符串, i, 1)
- If "A" <= s And s <= "Z" Then
- Ret(0) = Ret(0) + 1
- ElseIf "a" <= s And s <= "z" Then
- Ret(1) = Ret(1) + 1
- ElseIf "0" <= s And s <= "9" Then
- Ret(2) = Ret(2) + 1
- Else
- Ret(3) = Ret(3) + 1
- End If
- Next
- 字串计数 = Ret
- End Function
- SmAssert.That 字串计数("*'&ABCDabcde12345") ,"in", Array(4,5,5,3)
- SmAssert.That 字串计数("bgA5<1d-tOwUZTS8yQ") ,"in", Array(7,6,3,2)
- SmAssert.That 字串计数("@mw>0=QD-iAx!rp9TaG?o&M%l$34L.nbft") ,"in", Array(7,13,4,10)
复制代码 【插件下载】【插件】神梦断言插件 SmAssert.dll,帮助开发者发现业务逻辑错误
|