鸭,鸭,走了!


40

这是(非常可怕的)五只小鸭子的歌(不长):

Five little ducks went out one day,
over the hills and up away.
Mother Duck said, "Quack Quack Quack Quack",
but only four little ducks came back.

Four little ducks went out one day,
over the hills and up away.
Mother Duck said, "Quack Quack Quack Quack",
but only three little ducks came back.

Three little ducks went out one day,
over the hills and up away.
Mother Duck said, "Quack Quack Quack Quack",
but only two little ducks came back.

Two little ducks went out one day,
over the hills and up away.
Mother Duck said, "Quack Quack Quack Quack",
but only one little duck came back.

One little duck went out one day,
over the hills and up away.
Mother Duck said, "Quack Quack Quack Quack",
but none of the little ducks came back.

Mother duck herself went out one day,
over the hills and up away.
Mother Duck said, "Quack Quack Quack Quack",
and all of the little ducks came back.

您的任务是不输出这首歌。您应该拿一个经文并输出下一个经文(最后一个经文的下一个经文是第一个经文)。

规则

  • 请没有标准漏洞。
  • 输入/输出将通过我们的标准输入/输出方法进行。
  • 精确的诗句必须输出,相比歌词时,不应该有差别。将其与歌曲歌词进行比较时,输入也不会有所不同。

例子

Mother duck herself went out one day,
over the hills and up away.
Mother Duck said, "Quack Quack Quack Quack",
and all of the little ducks came back.

预期:

Five little ducks went out one day,
over the hills and up away.
Mother Duck said, "Quack Quack Quack Quack",
but only four little ducks came back.

Three little ducks went out one day,
over the hills and up away.
Mother Duck said, "Quack Quack Quack Quack",
but only two little ducks came back.

预期:

Two little ducks went out one day,
over the hills and up away.
Mother Duck said, "Quack Quack Quack Quack",
but only one little duck came back.

22
我记得许多月前我年轻时所说的话略有不同。但是我也记得受到它的创伤!那些日子里那些失踪的小鸭子在哪里?为什么没人出去找他们?什么样的不负责任的母亲设法失去了这么多孩子,并一直让其余的孩子出去玩呢!惊恐的事件!
毛茸茸的

8
可能重复。开玩笑的是:)
Night2

7
你只是吓呆了我。
A _

2
那首歌的歌词肯定使我感慨万千。
Num Lock

2
我听了昨天在这里发布的YouTube视频,两次,只是两次。现在,无论我走到哪里,无论做什么,我都会一直听着!帮助...
Night2

Answers:


3

STAX115个 111 字节

τ*^&k─Zè0µ9┬$█◘çl╟☼:Drσ59ò╠▄┴╢Q♂╔¡ô╜Oa╣▀yèA÷╨%^♀█Ö+╡◄ì=∙%╧o▌Θ<▲Çα¿╗√;1°┼╤V◘ú┐♥▒ÇM☼b╩░o]YaL4░ƒ%(Æ♫Q0æÆä⌂¡╘○Eâó╪¡

运行并调试

所有经文都作为测试用例


1
当您用“一只小鸭子”运行它时,它会回答“小鸭子中的小鸭子又回来了”。在最后一行。
多里安

1
该错误已免费修复。实际上,这大约是2字节的成本,并且在其他地方抵消了2字节的节省,尽管在这里字节​​很难测量,因为在压缩字符串文字中,甚至在最终程序中,更改都不是按字节对齐的。
递归

19

JavaScript(ES9),227字节

这与下面的“节点”版本相似,但是使用的公式基于parseInt()而不是Buffer()标识输入的经文。

这是ES2018(aka ES9),因为我们正在使用带有/s标记(dotAll)的正则表达式。

s=>'Mother duck herself1and all23,,Three4two3,Five4four3,Four4three3,One01but none23,Two4one0'.split`,`[parseInt(s,30)&7].replace(/\d/g,n=>[x=' little duck',y=/ w.*\n/s.exec(s),' of the',x+='s',x+y+'but only '][n])+s.slice(-11)

在线尝试!

怎么样?

在此版本中,我们将整个输入经节解析为以30为底数(0to t),并与7进行按位与运算。解析在第一个无效字符上停止,导致:

 verse | valid part | base 30 -> decimal | AND 7
-------+------------+--------------------+-------
   0   |  'fi'      |            468     |   4
   1   |  'fo'      |            474     |   2
   2   |  'three'   |       23973734     |   6
   3   |  't'       |             29     |   5
   4   |  'one'     |          22304     |   0
   5   |  'mother'  |      554838747     |   3

JavaScript(Node.js) 233,231,227 字节

@Shaggy节省了2个字节

s=>'Three4two3,Four4three3,Mother duck herself1and all23,One01but none23,,,Two4one0,,Five4four3'.split`,`[Buffer(s)[2]%9].replace(/\d/g,n=>[x=' little duck',y=/ w.*\n/s.exec(s),' of the',x+='s',x+y+'but only '][n])+s.slice(-11)

在线尝试!

怎么样?

每个输入节的第三个字符都可以用作唯一标识符。通过将其ASCII码取模9,我们得到:

 verse | 3rd char. | ASCII code | MOD 9
-------+-----------+------------+-------
   0   |    'v'    |     118    |   1
   1   |    'u'    |     117    |   0
   2   |    'r'    |     114    |   6
   3   |    'o'    |     111    |   3
   4   |    'e'    |     101    |   2
   5   |    't'    |     116    |   8

输出经文使用以下模板进行编码:

 verse | template
-------+---------------------------------
   0   | 'Five4four3'
   1   | 'Four4three3'
   2   | 'Three4two3'
   3   | 'Two4one0'
   4   | 'One01but none23'
   5   | 'Mother duck herself1and all23'

根据下表,其中每个数字都用字符串替换:

 digit | replaced with
-------+---------------------------------------------------
   0   | ' little duck'
   1   | / w.*\n/s.exec(s)
   2   | ' of the'
   3   | ' little ducks'
   4   | ' little ducks' + / w.*\n/s.exec(s) + 'but only '

正则表达式/ w.*\n/s从输入中提取此公共部分的位置:

  went out one day,[LF]
 over the hills and up away.[LF]
 Mother Duck said, "Quack Quack Quack Quack",[LF]

最后,我们添加输入的最后11个字符" came back."



1
@Shaggy很好。谢谢!
Arnauld

2
只是在发布另一条评论以建议exec页面何时重新加载。伟大的思想 ... !
毛茸茸的

11

Python 3中267个263 254字节

@ovs节省了4个字节

def f(s):
 for a in zip(T[2:]+T,T):s=s.replace(*a)
 return s
T="8:9:and allHO1BnoneHT2No1T3Nt2F4Nt3FiveINf4MotherD herself"
for r in "H of theI,4ourI,3hreeI,2woI,1neL:,ILs:,L littleD,D duck,NBonly ,Bbut ".split(','):T=T.replace(r[0],r[1:])
T=T.split(':')

在线尝试!

通过用下一节经文的各个部分替换相关部分来工作。

预初始化后T['8', '9', 'and all of the little ducks', 'One little duck', 'but none of the little ducks', 'Two little ducks', 'but only one little duck', 'Three little ducks', 'but only two little ducks', 'Four little ducks', 'but only three little ducks', 'Five little ducks', 'but only four little ducks', 'Mother duck herself']

替代Python 2,252字节

通过@ovs

lambda s:reduce(lambda s,a:s.replace(*a),zip(T[2:]+T,T),s)
T="8:9:and allHO1BnoneHT2No1T3Nt2F4Nt3FiveINf4MotherD herself"
for r in "H of theI,4ourI,3hreeI,2woI,1neL:,ILs:,L littleD,D duck,NBonly ,Bbut ".split(','):T=T.replace(r[0],r[1:])
T=T.split(':')

在线尝试!


for a in zip(T,T[-2:]+T):s=s.replace(*a)264个字节。
ovs

lambda s:reduce(lambda s,a:s.replace(*a),zip(T,T[-2:]+T),s)在Python中2 262个字节
OVS

@ovs谢谢,我改掉了一些东西,使用了T[2:]代替T[-2:]
Black Owl Kai


7

Java 10,347个字节

s->{String L=" little duck",M="Mother duck herself";int i=9;for(var t:("ive;Four;hree;Two"+L+"s;One"+L+";four;two"+L+"s;only one"+L+";but none;and all of the;"+M).split(";"))s=s.replace(t,++i+"");for(var t:("Five"+L+"s;but only four;and all;none of the"+L+"s;one"+L+";three;"+M+";One"+L+";wo;Three;our").split(";"))s=s.replace(i--+"",t);return s;}

在线尝试。

说明:

[10,21]

s->{                     // Method with String as both parameter and return-type
  String L=" little duck",M="Mother duck herself";
                         //  Two temp strings to save bytes
  int i=9;               //  Temp replacement integer, starting at 9
  for(var t:("ive;Four;hree;Two"+L+"s;One"+L+";four;two"+L+"s;only one"+L+";but none;and all of the;"+M).split(";"))
                         //  Loop over the parts to replace:
    s=s.replace(t,       //   Replace the part,
                ++i+""); //   with the integer pre-incremented by 1
  for(var t:("Five"+L+"s;but only four;and all;none of the"+L+"s;one"+L+";three;"+M+";One"+L+";wo;Three;our").split(";"))
                         //  Then loop over the parts to replace with in reverse:
    s=s.replace(i--+"",  //   Replace the (post-decrementing) integer,
    t);                  //   with the replacement-part
  return s;}             //  And then return the modified String as result

7

T-SQL,407个390 388 382字节

DECLARE @ CHAR(999)=REPLACE(REPLACE('SELECT CASE LEFT(v,2)WHEN''Fi74,''Four''),122,4,''three'')WHEN''Fo74,''Three''),123,5,''two'')WHEN''Th75,''Two''),121,16,''on#'')WHEN''Tw716,''On#''),115,20,''none of th#s'')WHEN''On715,''Mother duck herself''),115,8,''and all'')WHEN''Mo719,''Fiv#s''),113,14,''but only four'')END FROM i',7,'''THEN STUFF(STUFF(v,1,'),'#','e little duck')EXEC(@)

iVARCHAR(MAX)v

在保存了REPLACE两个字节后,将以下内容作为动态SQL执行:

SELECT CASE LEFT(v,2)
       WHEN'Fi'THEN STUFF(STUFF(v,1,4,'Four'),122,4,'three')
       WHEN'Fo'THEN STUFF(STUFF(v,1,4,'Three'),123,5,'two')
       WHEN'Th'THEN STUFF(STUFF(v,1,5,'Two'),121,16,'one little duck')
       WHEN'Tw'THEN STUFF(STUFF(v,1,16,'One little duck'),115,20,'none of the little ducks')
       WHEN'On'THEN STUFF(STUFF(v,1,15,'Mother duck herself'),115,8,'and all')
       WHEN'Mo'THEN STUFF(STUFF(v,1,19,'Five little ducks'),113,14,'but only four')END
FROM i

使用CASE语句和STUFF命令在列出的位置插入/覆盖字符。

编辑

  1. 用完全不同的策略替换原始文档(如下)
  2. 通过切换到LEFT而不是SUBSTRING消除空格来节省两个字节
  3. 通过将变量更改CHAR为并将第二个多余的字母移动到第二个字母,可以节省6个字节REPLACE(感谢@CDC!)

这是我的第一个版本,使用不同的方法(替换后,格式化):

DECLARE @ VARCHAR(MAX)
SELECT @=v FROM i
SELECT @=REPLACE(@,PARSENAME(value,2),PARSENAME(value,1))
FROM string_split('e.but none.and all
                  -e.One little duck.Mother duck herself
                  -o.only one little duck.none of the little ducks
                  -o.Two little ducks.One little duck
                  -r.two little ducks.one little duck
                  -r.Three.Two
                  -u.three.two
                  -u.Four.Three
                  -v.four.three
                  -v.Five.Four
                  -t.and all of the.but only four
                  -t.Mother duck herself.Five little ducks','-')
WHERE LEFT(value,1)=SUBSTRING(@,3,1)
PRINT @

STRING_SPLITPARSENAME用于通过-.分隔符将字符串分成行和列。

第一列是与输入经文的第三个字母匹配的键字符(感谢@ Night2)。第二和第三是为那节经文执行的替换。


第一种解决方案,如果使用“ CHAR(700)”而不是“ VARCHAR(MAX)”,则可以节省3个字节。另外,在你的“小鸭子”,可以改为做“E小鸭子”和#之前删除每个更换电子再弄3
CDC

顺便说一句,非常有趣的解决方案。我使用formatmessage与您非常接近,但不太接近。
CDC

好建议,@ CDC,谢谢!
BradC

6

Python 2,1034字节

这是我的代码!它使用一个简单的字典。运行此代码后,您可以输入任何经文,它将输出下一个经文。

PS:我是这个频道的新手,这是我的第一篇文章。我真的很喜欢这个挑战,因此决定尝试一下。请随时纠正我。

import sys
i=sys.stdin.readlines()
s={"Mother":"""Five little ducks went out one day,
over the hills and up away.
Mother Duck said, "Quack Quack Quack Quack",
but only four little ducks came back.""",
"Five":"""Four little ducks went out one day,
over the hills and up away.
Mother Duck said, "Quack Quack Quack Quack",
but only three little ducks came back.""",
"Four":"""Three little ducks went out one day,
over the hills and up away.
Mother Duck said, "Quack Quack Quack Quack",
but only two little ducks came back.""",
"Three":"""Two little ducks went out one day,
over the hills and up away.
Mother Duck said, "Quack Quack Quack Quack",
but only one little duck came back.""",
"Two":"""One little duck went out one day,
over the hills and up away.
Mother Duck said, "Quack Quack Quack Quack",
but none of the little ducks came back.""",
"One":"""Mother duck herself went out one day,
over the hills and up away.
Mother Duck said, "Quack Quack Quack Quack",
and all of the little ducks came back."""}
print s[i[0].split(" ")[0]]

11
欢迎光临本站!通常,我们会将字典视为来源的一部分。挑战的一部分将是尝试使其尽可能小。还有几种方法可以缩短此时间。1)由于您没有任何可读性,因此可以使用单个字符变量名称(例如xa)。2)Python在空格中相当宽容,因此我也尝试删除一些空格。例如,您不需要在周围加空格=。最后,我们有一个关于Python打高尔夫球的页面,您可以访问您的比赛。
小麦巫师

哇@ SriotchilismO'Zaic!这很有帮助..谢谢!:)
Prachiti Prakash Prabhu

1
您可以通过删除不必要的空格和变量轻松地进行高尔夫运动,避免sys使用例如raw_input(),缩短字典的键等方法进行导入。您绝对应该取出歌曲的重复部分,并分别添加它们
Jo King

正如我提到的,@ JoKing是我的第一篇文章,对此我并没有考虑太多。只是想尝试一下,但我现在明白了。我的下一篇文章将比这要好得多和短得多-谢谢大家..帮助我!:)
Prachiti Prakash Prabhu

6

PHP(7.4),253 247字节

通过在“拆开数组内部”的更多帮助下,改进替换数组的构建方式,可以减少-6个字节。

<?=strtr($argv[1],array_combine([0,1,...$a=[Five.$l=($o=" little duck").s,($b="but only ").four.$l,Four.$l,$b.three.$l,Three.$l,$b.two.$l,Two.$l,$b.one.$o,One.$o,"but none of the$l","Mother duck herself","and all of the$l"]],[...$a,$a[0],$a[1]]));

在线尝试!

这将以key=>value格式创建所有可能替换(12个已使用+ 2个未使用)的数组。示例:['Mother duck herself' => 'Five little ducks', etc...]然后仅使用strtr替换那些

唯一有趣的是我第一次使用“拆包内部数组”,这是PHP 7.4的新功能。


PHP,264字节

<?=str_replace(($a=[[Five.$l=($o=" little duck").s,($b="but only ").four.$l],[Four.$l,$b.three.$l],[Three.$l,$b.two.$l],[Two.$l,$b.one.$o],[One.$o,"but none of the$l"],["Mother duck herself","and all of the$l"]])[$i=strpos(vuroet,($v=$argv[1])[2])],$a[++$i%6],$v);

在线尝试!

我将每个经文的不同词存储在数组中。我发现输入使用的是第三个字符,因为它是唯一的(vuroet)。然后,我简单地用下一个经文的不同词替换该经文的不同词。


5

干净,352字节

import StdEnv,Text
$n={#"Five"+e+"four"+d,"Four"+e+"three"+d,"Three"+e+"two"+d,"Two"+e+"one"+a,"One"+a+b+"but none"+f,"Mother duck herself"+b+"and all"+f}.[indexOf{n.[2]}"tvuroe"]+" came back."
a=" little duck"
b=" went out one day,\nover the hills and up away.\nMother Duck said, \"Quack Quack Quack Quack\",\n"
d=a+"s"
e=d+b+"but only "
f=" of the"+d

在线尝试!



3

PowerShell中356个 343 340 336字节

param($p)$l,$M=' little duck','Mother duck herself'
("ive!our;four!three;hree!wo;Four!Three;two!one;s c! c;Two!One;s w! w;only one!none of the;k c!ks c;One$l!$M;but none!and all;$M!Five$l`s;and all of the!but only four"-split';')[$(switch -r($p){^Fi{0,1}^Fo{2,3}^Th{2,4,5}^Tw{6..9}^O{10,11}^M{12,13}})]|%{$p=$p-creplace($_-split'!')}
$p

在线尝试

更具可读性的版本:

param($p)
$l, $M = ' little duck', 'Mother duck herself'
$replacements = @"
ive!our
four!three
hree!wo
Four!Three
two!one
s c! c
Two!One
s w! w
only one!none of the
k c!ks c
One$l!$M
but none!and all
$M!Five$l`s
and all of the!but only four
"@ -split '\n'
$i = switch -regex ($p) { ^Fi { 0, 1 }
                          ^Fo { 2, 3 }
                          ^Th { 2, 4, 5 }
                          ^Tw { 6..9 }
                          ^O  { 10, 11 }
                          ^M  { 12, 13 } }
$replacements[$i] | % { $p = $p -creplace ( $_ -split '!' ) }
$p

3

PowerShell中265个 263 255 251 246字节

$d='Five1four2s,Four1three2s,Three1two2s,Two1one2,One23but none52s,Mother duck herself3and all52s'-split','
'2s34',' little duck',-join($args-split'(\s)')[5..39],'but only ',' of the'|%{$d=$d-replace++$i,$_}
$d[+"$args"[2]*37%724%7]+' came back.'

在线尝试!

我用蛮力找到了表达+"$args"[2]*37%724%7

 verse | 3rd char. | ASCII code | *37%724%7
-------+-----------+------------+-----------
   0   |    'v'    |     118    |   1
   1   |    'u'    |     117    |   2
   2   |    'r'    |     114    |   3
   3   |    'o'    |     111    |   4
   4   |    'e'    |     101    |   5
   5   |    't'    |     116    |   0

感谢@Arnauld的帮助3rd char


2

Japt v2.0a0,143 字节

尝试对单节经文进行替换编码,但最后,适应Arnauld的解决方案最终变得更短。有另一个想法可能希望再缩短一次,但不知道何时才能尝试。

tBn)i`Fr4È(e3
Two4e0
MÇ@r Ýõ Êelf1d a¥23
O01¿t Í
23
TËG4two3
Five4fr3`·g`v`b¢Î)r\dÈ°g[V=` Ò¤ Ýõ`W=Uf/ w.*\n/s `  e`V±'sV+W+`¿t § `]

尝试 -包括所有经文


2

373个 355字节

这里没有什么太疯狂的。减少几个字节的简单方法就是用单个字符替换两个字符的变量(a1,a2,a3,e1..e6)。

read a{1..3} b
read c
read d
read e{1..6}
W="$e1 $e2"
X="${e3^} $a2 $a3"
Y="$e5 $e6"
Z="$e4 $Y"
p=$X
case $a1 in M*)p="Five ${Y::12}";s="but only four $Y";;O*)p="${d::11} herself";s="and all of $Z";;Tw*)p=${X/s};s="$e1 none of the $a2 ducks $e6";;Th*)s="$W one $e4 duck $e6";;Fo*)s="$W two $Z";;Fi*)s="$W three $Z";;esac
echo $p $b;echo $c;echo $d;echo $s

在线尝试!

在线尝试!


2

05AB1E,134字节

“€µ‚•„í†ìˆÈ“#’ „ê Ðœs’δJ樅î¥Ðœº¶s‚ìðδJD…€³€É δ쨦“€ƒ€Ÿ€‚€€““€³Šª€‚€€“‚’ „ê Ðœs ’δJ셋邃.δJU.•4Ôāl•|н2èk©è.ª?I„ 
ý#3.$17£ðý„ 
¶:,X®è?

在线尝试!

由于我是05AB1E的新手,因此可以打很多球

                ### Preparation of the output strings ###
“€µ‚•„í†ìˆÈ“        push "one two three four five"
#                   split that by spaces
’ „ê Ðœs’           push " little ducks"
δJ                  join each number with " little ducks"
ć¨                  separate "one little ducks" and drop the "s"
…î¥Ðœº¶             push "mother duck herself"
s                   swap it with "one little duck"
‚ì                  prepend both strings to the list ["mother duck herself", "one little duck", "two little ducks" ... ]
ðδJ                 append a space to each list entry
D                   duplicate it
…€³€É               push "but only "
δì                  prepend "but only " to each list entry
¨¦                  drop the first and last list entry
“€ƒ€Ÿ€‚€€“          push "and all of the"
“€³Šª€‚€€“          push "but none of the"
‚                   push the two strings into a list
’ „ê Ðœs ’δJ        append " little ducks " to each
ì                   prepend it to the sentence list ["and all of the little ducks ", "but none of the little ducks ", "but only one little duck " ...]
…‹é‚ƒ.              push "came back."
δJ                  append that to each list entry
U                   save that list in X for later use

                ### Determine which verse has to be answered ###
.•4Ôāl•             push "eoruvt"
|н2è                get the third letter of the input
k                   get the index of that letter in "eoruvt". Now we know which verse we must return
©                   save that index in ® for later use

                ### Print the answer strings ###
è.ª?                print that index of the first sentence list (first three words of answer)
I„                  join the four input strings by <space><newline>
ý
#                   split that by spaces
3.$                 cut off the first three words
17£                 keep only the next 17 words
ðý                  join remaining words by spaces
„ 
¶:                  replace <space><newline> by only <newline>
,                   print that ("went out ... Quack\",") 
X®è?                print the last line of answer

1

Perl 6、247字节

{S:i/ne\sl.*?<(s//}o{m/..(.)(\S*)**3%\s(.**92).*(.**11)/;[(my$l=" little ducks")~$3 XR~"Mother duck herself$2and all of the","One{$l~=$2}but none of the","Five{$l~="but only "}four","Four{$l}three","Three{$l}two","Two{$l}one"]["eotvur".index($0)]}

在线尝试!

绝对可以打高尔夫球,尤其是列表中的最后5个元素"num $l num-1",或与旧输入的正确部分匹配的起始正则表达式。


1

木炭,156字节

≔⌕tvuroe§θ²δ§⪪”↶0∨↘»≔xj➙⌈´βXPNLA‽⟦O⧴&▷V'¦³≧ψZρ⊞t”¶δF‹δ⁵”↶↧V4ⅉH‴G%”F‹δ⁴s⮌…⮌θ¹⁸⸿η⸿ζ⸿§⪪”}∧h⁴NQ≕Q^⪫ΦG✂q'ⅉMG./_⸿s⁵6P⁴″⊟±NNpOfBz↷Fι‖TM→⁻γ?k⁴ς!d⁵º'E,θ}x§-υ”¶δ✂ε±¹¹

在线尝试!链接是详细版本的代码。说明:

≔⌕tvuroe§θ²δ

看第一行的第三个字符,算出我们想要的经文。

§⪪”↶0∨↘»≔xj➙⌈´βXPNLA‽⟦O⧴&▷V'¦³≧ψZρ⊞t”¶δF‹δ⁵”↶↧V4ⅉH‴G%”F‹δ⁴s⮌…⮌θ¹⁸

输出的第一行通过索引到字符串列表的第一部分FiveFourThreeTwoOneMother duck herself。然后打印little ducks根据需要打印,然后输入行的最后18个字符(每节经文始终相同)。

⸿η⸿ζ⸿

每节经文的中间两行总是相同的。

§⪪”}∧h⁴NQ≕Q^⪫ΦG✂q'ⅉMG./_⸿s⁵6P⁴″⊟±NNpOfBz↷Fι‖TM→⁻γ?k⁴ς!d⁵º'E,θ}x§-υ”¶δ✂ε±¹¹

对于最后一行,出于little ducks某种原因,将其包含在替代项列表中显得更加熟练,但是最后11个字符仍会从输入中复制。


1

墨水,353字节

=d(v)
~temp n=(v?"Fi")+(v?"F")*4+(v?"Th")+(v?"T")*2+(v?"O")
{n-1:{n:{n-5:{n-4:{n-3:One|Two}|Three}|Four}|Five} little duck{n-2:s}|Mother duck herself} went out one day,
over the hills and up away,
Mother Duck said "Quack Quack Quack Quack",
{n-1:but {n-2:only {n:{n-5:{n-4:one|two}|three}|four}|none of the}|and all of the} little duck{n-3:s} came back.

在线尝试!

首先,使用子字符串检查来找出我们所处的经文-这很容易,这要归功于开头的数字大写- FT并且O不会在其他任何地方出现,并且您可以将第二和第四经文与通过检查FiTh分别。

然后,我们只用墨水做得最好,然后打印带有条件的纯文本。我最初尝试使用switch语句,但是虽然看起来更好,但实际上结束时间更长。
您可能会认为Quacks是使用变量的好地方,字符串要重复一堆,但是变量带来了足够的开销,以至于我试图做的每一种方式都使代码更长。也许这是我不应该打高尔夫球的迹象。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.