TSQL,267个字节
打高尔夫球:
USE master
DECLARE @ varchar(max)=
'## ##
### #
## %#
# ###
# ####'
WHILE @@rowcount>0WITH C as(SELECT x+1i,substring(@,x+1,1)v,x/z r,x%z c
FROM spt_values CROSS APPLY(SELECT number x,charindex(char(10),@)z)z
WHERE type='P'and x<len(@))SELECT @=stuff(@,d.i,1,'%')FROM C,C D
WHERE'#%'=d.v+c.v and abs(c.r-d.r)<2and abs(c.c-d.c)<2PRINT @
取消高尔夫:
USE master-- the script needs to be executed on the default master database
DECLARE @ varchar(max)=
'## ##
### #
## %#
# ###
# ####'
WHILE @@rowcount>0
WITH C as
(
SELECT x+1i,substring(@,x+1,1)v,x/z r,x%z c
FROM
spt_values
CROSS APPLY(SELECT number x,charindex(char(10),@)z)z
WHERE type='P'and x<len(@)
)
SELECT @=stuff(@,d.i,1,'%')FROM C,C D
WHERE'#%'=d.v+c.v and abs(c.r-d.r)<2and abs(c.c-d.c)<2
PRINT @
试试看