Powershell,111102字节
param($s)$s+'.'*!($s-match'[1-57]|0$|'+-join$(switch -r($s[($s.Length-1)..0]){'0|8'{$_}'6'{9}'9'{6}}))
解释测试脚本:
$f = {
param($s) # input string
$l=$s.Length # length of the string
$c=$s[($l-1)..0] # chars of the string in the reversed order
$d=switch -r($c){ # do switch with regex cases for each char
'0|8'{$_} # returns the current char if it equal to 8 or 0
'6'{9} # returns 9 if the current char is 6
'9'{6} # returns 6 if the current char is 9
} # returns array of new chars (contains 0,6,8,9 only)
$s+'.'*!( # returns s. Add '.' if not...
$s-match'[1-57]|0$|'+-join$d
# $s contains chars 1,2,3,4,5,7 or
# ends with 0 or
# equal to string of $d
)
}
@(
,('2' ,'2' )
,('4' ,'4' )
,('5' ,'5' )
,('6.' ,'6' )
,('7' ,'7' )
,('9.' ,'9' )
,('16' ,'16' )
,('60' ,'60' )
,('66.' ,'66' )
,('68.' ,'68' )
,('69' ,'69' )
,('906' ,'906' )
,('909.' ,'909' )
,('8088.','8088')
,('9806.','9806')
,('9886' ,'9886')
,('9889.','9889')
) | % {
$e,$s = $_
$r = &$f $s
"$($r-in$e): $r"
}
输出:
True: 2
True: 4
True: 5
True: 6.
True: 7
True: 9.
True: 16
True: 60
True: 66.
True: 68.
True: 69
True: 906
True: 909.
True: 8088.
True: 9806.
True: 9886
True: 9889.
60
应该60.
吗?