奥利奥?不,棒棒糖,也许吗?


46

自2009年以来,Android的版本代码名称一直以糖果为主题。Android 1.5是Cupcake,Android 1.6是Donut,Android 2.0是Eclair,等等。实际上,版本名称是字母顺序的!

C -> Cupcake
D -> Donut
E -> Eclair
F -> Froyo
G -> Gingerbread
H -> Honeycomb
I -> Ice Cream Sandwich
J -> Jellybean
K -> Kitkat
L -> Lollipop
M -> Marshmallow
N -> Nougat
O -> Oreo

为了:

Cupcake, Donut, Eclair, Froyo, Gingerbread, Honeycomb, Ice Cream Sandwich, Jellybean, Kitkat, Lollipop, Marshmallow, Nougat, Oreo

挑战

写一个程序/功能是需要从一个字母C到O并输出其各自的Android版本代号。

技术指标

  • 适用标准I / O规则。
  • 标准的漏洞被禁止。
  • 您可以选择支持小写输入或大写输入,甚至两者都支持。
  • 输出可能是标题大写(Cupcake)或完全小写(eclair)。Ice cream sandwich可能大写,但是您喜欢。(我没想到它会引起太多混乱...)
  • 挑战不是要找到所有语言中最短的方法,而是要找到每种语言中最短的方法。
  • 除非另有说明,否则您的代码通常以UTF-8编码形式以字节计分。
  • 允许使用内置函数(Mathematica可能具有一个:P)来计算此序列,但鼓励使用不依赖内置函数的解决方案。
  • 鼓励甚至对“实用”语言进行解释。

测试用例

这些是大写和标题大小写。

Input   Output

F       Froyo
I       Ice Cream Sandwich
J       Jellybean
N       Nougat
G       Gingerbread
L       Lollipop

有几种更好的格式:

F, I, J, N, G, L
f, i, j, n, g, l

F I J N G L
f i j n g l

8
@ Mr.Xcoder您是说它不是骗子,因为它更容易吗?这是一个骗局,恰恰是因为它是现有问题的简单版本。我们已经将这类问题弄死了,而这一问题绝对不会为该类型提供新的或有趣的东西。
— 小麦巫师

2
@WheatWizard我认为前者是一个更好的骗子,因为后者是受限制的来源。
— Xcoder先生17年

9
这可能是对其他挑战的愚弄。但是,请帮助我认识到我的怪物正在要求将字符串转换为符号(这导致基于哈希的解决方案)。这是要求符号串。
— Arnauld


5
@MagicOctopusUrn是的,我也看到了。不幸的是,它不包含MARSHMALLOW和以后的版本。
— mbomb007 '17

Answers:


14

木炭,73字节

θ§⪪”%↖↙1¬¢/vy⁵⸿ψJPP±≔S×5Jρνξ–Gu ◧;Yx³F▶ψ;εB↥:P¹N﹪J$α✂χ✳⦄⟲*±¶Sp:ς↘V◧◧”x℅θ

在线尝试!I / O是小写的。基于此详细版本。说明:

                Implicitly print:
θ               Input character
                Implicitly print:
   ”...”        Long compressed string "oneycombx...xingerbread"
  ⪪            Split on
        x       The string "x"
 §              Circularly indexed by
          ℅     Character code of
           θ    Input character

4
我...什么 怎么样。
— 魔术八达通Ur

@MagicOctopusUrn抱歉,我当时太忙,无法添加说明。希望这个就足够了。
— 尼尔

1
哦,我不知道它压缩了字符串!
— 魔术章鱼缸

木炭在这里如何击败SOGL简直令人难以置信。
— 暴民埃里克(Erik the Outgolfer)'17年

果冻仍在击败它:欢乐:codegolf.stackexchange.com/a/140092/73675
— Hugo H

14

击+核心的Utils 131个 128 122 117字节。

该脚本编码为Base64,因为它包含特殊(怪异)字符。

仅以小写形式接受Android代号字母作为其第一个位置参数。还以小写形式返回完整的代号。

CiPBUeICicG5tJ8W5a0Pc/hYuw7hkNMSIYkAPjARkdgFrdbh3NJgTmB4gRPiiQDJAaOyBH4ki14C
QDeKRNQJ8IJYER411DAnx0SO4CAKYmFzZTMyICQwfHRyICdBLVo0NwonICdhLXoKICd8Z3JlcCBe
JDEK

说明:

#�Q��������s�X����!�>0�������`N`x������~$�^@7�D�    ��X5�0'�D�� 
base32 $0|tr 'A-Z47
' 'a-z
 '|grep ^$1
  • 前两行是包含数据的二进制Blob(有关更多信息,请参见答案的结尾)。第一行是空的,以避免Bash出现问题,否则它可能会认为正在使用二进制文件进行输入。
  • base32 $0 使用Base32编码脚本内容,默认换行符为76个字符。
  • tr 'A-Z47\n' 'a-z\n '(请注意,\n被写为字面换行符)将小写输入和替换4,7和\n通过\n,空间和空间分别。
  • grep ^$1 将输出与作为脚本第一个参数提供的字符串匹配的行。

二进制数据

此八位位组流是伪造的,因此不包含换行符,并且当根据RFC 4648用Base32对其进行解码时,结果字符串是Android代号的列表(使用4作为项目定界符,并使用7代替空格字符)。它的特殊之处在于它以换行符和哈希(#)开头,因此它表现为注释,因此不被解释器执行。

另外,此Base32实现的默认换行符可以换成76个字符,这对我帮助了一个字节,因为我对项目进行了重新排序以将换行符用作Ice Cream Sandwich空间之一。


此外,和去一点题外话,我认为谷歌应该不会在直接发布商业产品在Android代号。


2
很好,这是一个很酷的答案!欢迎来到网站:)
— DJMcMayhem


1
这个版本有错误,至少在我的系统上是这样(bash 4.4.12,coreutils 8.27)。为此f,它输出两行:一行froyo和另一行与mystery fgeyltmuzteibno。
— MarSoft

1
@MarSoft:谢谢!固定。可惜的是现在我还需要一个字节。
— Helio,

@MarSoft:解决了!现在具有相同的字节!
— Helio,

11

Python 3,139字节

lambda x:x+'upcake,onut,clair,royo,ingerbread,oneycomb,ce cream sandwich,ellybean,itkat,ollipop,arshmallow,ougat,reo'.split(",")[ord(x)-67]

在线尝试!


11

Bash +核心实用程序(Grep):132130字节

可能很简单

grep ^$1<<<'Cupcake
Donut
Eclair
Froyo
Gingerbread
Honeycomb
Ice Cream Sandwich
Jellybean
Kitkat
Lollipop
Marshmallow
Nougat
Oreo'

1
输入dd法巧妙,但您可以另存为脚本并$1改用吗?
— 唐·黑斯廷斯

11

果冻,57字节

Oị“¡ȥọ⁴ḷæĿɱ}#n#i®ÞSỊ3ƙɼıjṁ)-⁵g7ḥjC?4ƘẠʂ+ḋ¤⁺jṣð£?v»Ḳ¤F⁾! y

在线尝试!

-5感谢Jonathan Allan。


通过在“冰淇淋三明治”中的空格使用占位符并使用空格进行拆分来节省四个字节,例如:Oị“¡ḟ¤Y7bh%XO€ḥıṣẎṄṢ°ḊḞİỌĿż0Y⁷ẠỵƈƭV>tÐNY_LɠðṅẒọX?v»Ḳ¤F⁾! y
— Jonathan Allan

...实际上是使这五个字节(当词典中有“ clair”时,我曾使用“ lair”):Oị“¡ȥọ⁴ḷæĿɱ}#n#i®ÞSỊ3ƙɼıjṁ)-⁵g7ḥjC?4ƘẠʂ+ḋ¤⁺jṣð£?v»Ḳ¤F⁾! y
— Jonathan Allan

@JonathanAllan谢谢...等等,我为什么需要这个F?哦,这是因为我以字符串形式输入而不是char
— Outgolfer的Erik

8

C ++,206个 201 198字节

感谢@sergiol帮助节省了3个字节!

#import<cstdio>
void f(int l){char*w[]={"upcake","onut","clair","royo","ingerbread","oneycomb","ce Cream Sandwich","ellybean","itkat","ollipop","arshmallow","ougat","reo"};printf("%c%s",l,w[l-67]);}

在线尝试!

C,173字节

f(l){char*w[]={"upcake","onut","clair","royo","ingerbread","oneycomb","ce Cream Sandwich","ellybean","itkat","ollipop","arshmallow","ougat","reo"};printf("%c%s",l,w[l-67]);}

好吧,它最初是C ++,但现在它也是有效的C,可以将其编译为C来保存一些字节。

在线尝试!


1
我通过删除每个条目的第一个字母来使它变短的尝试失败:tio.run/…–
— sergiol

@sergiol谢谢!打了些高尔夫球之后,我得以节省了三个字节。
— Steadybox '17

4
#import在C ++中?我在这里想念什么?
— Abhinav Gauniyal

@AbhinavGauniyal:IIRC我认为一些编译警告,劝我也补充#import <cstdio>因为缺乏#include <stdio.h>; 或者可能是我错了
— sergiol

@AbhinavGauniyal这不是标准的C ++,但至少GCC和MSVC拥有它。
— Steadybox

7

JavaScript(ES6),137 136字节

感谢Neil,节省了1个字节

c=>'CupcakeDonutEclairFroyoGingerbreadHoneycombIce Cream SandwichJellybeanKitkatLollipopMarshmallowNougatOreo'.match(c+'([a-z]| .)+')[0]

演示版


您是否不能在字符范围中包含空格(可能是\ s)?
— 没用

1
@ michi7x7除冰淇淋三明治的情况外,他需要匹配以大写字母停止,尽管([a-z]| .)+(保存1个字节)即使在字符串中间使用冰淇淋三明治也可以工作(当代码名称到达S时,它将开始失败)虽然)。
— 尼尔

@Neil好,[a-z\s]+与大写字母不匹配。我只是不知道您是否可以在JS中做到这一点
— michi7x7

@ michi7x7那么它如何与冰淇淋三明治一起使用?
— 尼尔

2
使用Ice cream sandwich,例如在测试案例中使用(尽管这不是标题案例)
— michi7x7

5

Japt,81 79字节

包含一些此处不会显示的字符。

U+`Æ+tfÆ÷¯kef©fclairfê $ßdfey¬mbf­ ×Äm ÑØrfÁKÞ fkfo¥ipopfÂâÚaow`qf gUc

测试一下

  • 感谢Oliver节省了2个字节。

说明

大写字符串的隐式输入U。

名称的压缩字符串(反引号之间的所有字符),以f和分隔,且没有第一个字母,将被拆分(q)为on上的数组f。

在该数组中,我们获得s字符代码的索引(g)处的元素U。(是的,索引包装!)

我们将其附加U并隐式输出结果字符串。


1
真好 如果分割成两行,则可以节省几个字节f:ethproductions.github.io/japt/…–
— Oliver

@Oliver:哦,太好了,谢谢:)在我的电话上,走在街上绝对不是一会儿(即使有的话)。
— 毛茸茸的

5

Excel VBA中,137 134 132个字节

匿名VBE立即窗口函数,将输入作为预期的类型Variant\String和长度,并1保留单元格中的大写字母,[A1]然后输出到VBE立即窗口函数

?[A1]Split("upcake onut clair royo ingerbread oneycomb ce cream sandwich ellybean itkat ollipop arshmallow ougat reo")(Asc([A1])-67)

-5用于改变空格字节ce cream sandwich从(炭32)至 (炭160) 在``(炭127)和移除逗号分隔符Split功能


4

SOGL V0.12,81 个字节

]&ŗ√‰fō¶č▓'▼$»3↕█γb└a}⅟∑─b¹¦Æ:↕┘∞½Σ#gī±⅔≡≥\3Qy-7todΥ7ā‼D←εPρρ:¬c‰ƨ}f沑θ╔@ŗz,WHHw

在这里尝试!

说明:

...‘            push "cupcake donut eclair froyo gingerbread honeycomb ice_cream_sandwich jellybean kitkat lollipop marshmallow nougat oreo"
    θ           split on spaces
     ╔@ŗ        replace underscores with spaces
        z,W     find the inputs index in the lowercase alphabet
           HH   decrease by 2
             w  get that item from the array

现在有一个较短的80字节版本,但是由于这一挑战,我添加了+ 2 / -2内置函数:p

压缩后的字符串像"cup","cake"," donut eclair fro","yo gingerbread honeycomb ice","_","cream","_","sandwich jelly","bean kit","kat loll","i","pop marsh","mallow"," nougat oreo"最大程度地使用英语单词一样进行了拆分(许多不是在SOGL词典中),现在我找不到任何改进。


4

> <>,181个字节

!vi:od5*-0$6a*@p!
v<
 v"upcake"
 v"onut"
 v"clair"
 v"royo"
 v"ingerbread"
 v"oneycomb"
 v"ce Cream Sandwich"
 v"ellybean"
 v"itkat"
 v"ollipop"
 v"arshmallow"
 v"ougat"
 v"reo"
o<>

在线尝试!

这是通过自我修改程序以<在要打印的正确名称之前放置a 来实现的,该名称的位置由输入字母的值确定。


3

Dyalog APL,158个 143 131字节

@Zacharý节省了1个字节

@Gil节省了12个字节

{⍵,(⎕A⍳⍵)⊃','(1↓¨=⊂⊢)',,,upcake,onut,clair,royo,ingerbread,oneycomb,ce Cream Sandwich,ellybean,itkat,ollipop,arshmallow,ougat,reo'}

在线尝试!

怎么样?

',,,upcake...' -单词列表

','(1↓¨=⊂⊢) -除以 ','

(⎕A⍳⍵)⊃ -从字母中的论点位置代替

⍵, -并附加到信上


你为什么形容↑为扁平?
— 扎卡里

此外,{⍵,∊⍬⍬'upcake' 'onut' 'clair' 'royo' 'ingerbread' 'oneycomb' 'ce cream sandwich' 'ellybean' 'itkat' 'ollipop' 'arshmallow' 'ougat' 'reo'[⎕A⍳⍵]}少工作1个字节!
— 扎卡里

@Zacharý,因为它是“混合”。好东西!为什么∊而不是↑?
— Uriel's

因为∊也会变平,但实际上变平而不是“混合”。↑(1 2)(3 4)不平坦,而平坦∊(1 2)(3 4)。
— 扎卡里

@ZacharýOP改变了……再次。
— Uriel's

3

EXCEL,154个字节

=A1&CHOOSE(CODE(A1)-66,"upcake","onut","clair","royo","ingerbread","oneycomb","ce Cream Sandwich","ellybean","itkat","ollipop","arshmallow","ougat","reo")

我从未想过以这种方式使用excel。完善。现在使用WORD进行处理
— tisaconundrum

@tisaconundrum-我们不谈论那件事。甚至VBA也无法保存它
— 泰勒·斯科特

3

C(GCC) ,195个 192 190字节

-2字节感谢@Quentin

*V[]={"upcake","onut","clair","royo","ingerbread","oneycomb","ce Cream Sandwich","ellybean","itkat","ollipop","arshmallow","ougat","reo"};main(c,v)char**v;{printf("%c%s",c,V[(c=*v[1])-67]);}

在线尝试!


3

Tcl,158字节

proc A s {puts $s[lindex {upcake onut clair royo ingerbread oneycomb "ce Cream Sandwich" ellybean itkat ollipop arshmallow ougat reo} [expr [scan $s %c]-67]]}

在线尝试!


2
Tcl!您在这里看不到太多的Tcl解决方案。这是一个耻辱。
— 西尔维奥·马约洛

2

Haskell,145个字节

f c=takeWhile(/=succ c)$dropWhile(/=c)"CupcakeDonutEclairFroyoGingerbreadHoneycombIce Cream SandwichJellybeanKitkatLollipopMarshmallowNougatOreo"

3
takeWhile可以fst.span并且dropWhile相应地snd.span。
— Laikoni'8

2

盖亚 110字节

:c“reo“upcake“onut“clair“royo“ingerbread“oneycomb“ce Cream Sandwich“ellybean“itkat“ollipop“arshmallow“ougat”=+

在线尝试!

说明

:          Push two copies of the input
 c         Get the codepoint of the top one
  “...”    Push the list of version names without their first letters
       =   Modularly index the code point into the list
        +  Append to the input

2

Ruby,127个字节

->c{c+%w[upcake onut clair royo ingerbread oneycomb ce\ Cream\ Sandwich ellybean itkat ollipop arshmallow ougat reo][c.ord-67]}

接受大写输入。在线尝试!


2

Pyth,117个 116字节

我的Python回答的端口。

+Q@c"upcake,onut,clair,royo,ingerbread,oneycomb,ce cream sandwich,ellybean,itkat,ollipop,arshmallow,ougat,reo"\,a67C

在这里尝试!或签出测试套件

Pyth,99个字节(70个字符)

-15个字节,感谢@insert_name_here!

+Q@c." y|çEC#nZÙ¦Y;åê½9{ü/ãѪ#¤
ØìjX\"¦Hó¤Ê#§T£®úåâ«B'3£zÞz~Уë"\,a67C

在这里尝试!


通过使用压缩字符串,您可以节省15个字节(尽管答案必须包含不可打印的字符)。
— insert_name_here

@insert_name_here谢谢。
— Xcoder先生17年

2

Java(OpenJDK 8),128字节

c->c+"upcake#onut#clair#royo#ingerbread#oneycomb#ce Cream Sandwich#ellybean#itkat#ollipop#arshmallow#ougat#reo".split("#")[c-67]

在线尝试!


使用正则表达式,149个字节

s->"CupcakeDonutEclairFroyoGingerbreadHoneycombIce cream sandwichJellybeanKitkatLollipopMarshmallowNougatOreo".replaceAll(".*?("+s+"[a-z ]+).*","$1")

在线尝试!

  • 凯文·克鲁伊森(Kevin Cruijssen)在正则表达式解决方案上节省了4个字节!

1
.split当我阅读质询并找不到Java答案时(直到我进入答案的第二页),我将要发布相同的答案(仅使用不同的定界符),因此+1。至于正则表达式的答案,([a-z]| .)+可以是[a-z ]+,因为您可以输出“冰淇淋三明治”(“ 输出可以是标题大写(Cupcake)或完全小写(小饼)。冰淇淋三明治可以大写,但是您喜欢。 (我没想到它会引起如此大的混乱...) ”)
— Kevin Cruijssen

2

大概是1047 852 830字节

功能肯定可以帮助高尔夫大型程序...

⇒+552
⇒+551
⇒+553
⇒+55
⇒/1+52
⇒/1+53
~@7+4f5=?{:5+53@:4/1f1@:5+51@:5+2/1f4@:5+3/1f2@:2/1f2@}
+5f5=?{:3/1f1@:2/1f1@:5+53@:5+3/1f1@}
+51f5=?{:5+51@+1@:5+2/1f4@:5+1/1+551@+1@}
+52f5=?{:5+1/1f1@:3/1f1@:4/1f3@:3/1f1@}
+53f5=?{:5+1/1f2@:2/1f1@:4/1f2@:2/1f2@:5+1/1f1@:5+3/1f4@:5+1/1f1@:2/1f2@:5+2/1f4@:1/1f2@}
+53=?{:3/1f1@:2/1f1@-1@:4/1f3@:5+51@:3/1f1@:1/1f1@:5+3/1f4@}
+1f6=?{:5+51@:2/1f2@:5/1+3@:4/1+52@:5+1/1f1@:2/1f2@:5+2/1+55@:1/1f1@:5/1+3@:2/1+54@:5+2/1f4@6:2/1f1@6:1/1f2@6:2/1f3@6:5+1/1f2@6:5+51@6:5/1f2@6}
+2f6=?{:2/1f2@:5+52@@:4/1f3@:5+3/1f4@:2/1f2@:5+2/1f4@:2/1f1@}
+3f6=?{:5+1/1f2@:5+3/1f1@-1@:5+2/1f4@:5+3/1f1@}
+4f6=?{:3/1f1@:5+52@@:5+1/1f2@:4/1f1@:3/1f1@:4/1f1@}
+5f6=?{:5+2/1f4@:5+1/1f1@:5+2/1f1@:5/1f2@:1/1f1@:5+2/1f4@:5+52@@:3/1f1@:2/1f3}
+51f6=?{:3/1f1@:5+53@:4/1f2@:5+2/1f4@:5+3/1f1@}
+52f6=?{:5+1/1f1@:2/1f2@:3/1f1@}

在线尝试!在Cubically的SBCS中为830字节。

  • ~读取输入,然后@打印。(当输入无效时,这会中断。)
  • 中的每一个+.../...+...=7?6{...}的输入进行比较,以每个ASCII值(C,D,E,F,等等),并执行中的代码{...},如果它们是相等的。
  • 每个代码块({...})打印其余名称(第一个字符已打印)。

感谢TehPers将ASCII转换为Cubically的翻译器,它非常有帮助。


1
那是1060字节
— Conor O'Brien

1

V,125字节

Ccupcake
donut
eclair
froyo
gingerbread
honeycomb
ice cream sandwich
jellybean
kitkat
lollipop
marshmallow
nougat
oreoÇ^"/d

在线尝试!


1

派克,117字节

我的Python回答的端口。

"upcake,onut,clair,royo,ingerbread,oneycomb,ce cream sandwich,ellybean,itkat,ollipop,arshmallow,ougat,reo"\,cQ.o67-@+

在这里尝试!

被编码为十六进制代码的Pyke高尔夫新技术为116字节:

22 75 70 63 61 6B 65 2C 6F 6E 75 74 2C 63 6C 61 69 72 2C 72 6F 79 6F 2C 69 6E 67 65 72 62 72 65 61 64 2C 6F 6E 65 79 63 6F 6D 62 2C 63 65 20 63 72 65 61 6D 20 73 61 6E 64 77 69 63 68 2C 65 6C 6C 79 62 65 61 6E 2C 69 74 6B 61 74 2C 6F 6C 6C 69 70 6F 70 2C 61 72 73 68 6D 61 6C 6C 6F 77 2C 6F 75 67 61 74 2C 72 65 6F 22 5C 2C 63 51 EF 36 37 2D 40 2B

(粘贴并检查Use hex encoding?)。


1
Pyke需要内置的“ Android版本”吗?
— 暴民埃里克(Erik the Outgolfer)'17年

1
@EriktheOutgolfer有口袋妖怪,为什么不呢?
— Xcoder先生17年

1

C# ,147个 136 129字节


数据

  • 输入 Char c版本名称的首字母
  • 输出 String版本的全名

打高尔夫球

// Requires the input to be uppercase.
// This is the one counting for the challange
c=>c+"upcake,onut,clair,royo,ingerbread,oneycomb,ce Cream Sandwich,ellybean,itkat,ollipop,arshmallow,ougat,reo".Split(',')[c-67];

// Optional. Requires the input to be lowercase.
c=>c+"upcake,onut,clair,royo,ingerbread,oneycomb,ce Cream Sandwich,ellybean,itkat,ollipop,arshmallow,ougat,reo".Split(',')[c-99];

// Optional. Works with both uppercase and lowercase with the additional cost of 10 bytes.
c=>c+"upcake,onut,clair,royo,ingerbread,oneycomb,ce Cream Sandwich,ellybean,itkat,ollipop,arshmallow,ougat,reo".Split(',')[c-(c<99?67:99)];

不打高尔夫球

c =>
    c + "upcake,onut,clair,royo,ingerbread,oneycomb,ce Cream Sandwich,ellybean,itkat,ollipop,arshmallow,ougat,reo"
        .Split( ',' )[ c - 67 ];

非高尔夫可读

// Takes a char 
c =>
    // Appends the input letter to...
    c + 

    // ... the name in the resulting index of the subtraction of the char with 67 ('C'), or with 99 ('c') for the lowercase version
    "upcake,onut,clair,royo,ingerbread,oneycomb,ce Cream Sandwich,ellybean,itkat,ollipop,arshmallow,ougat,reo"
        .Split( ',' )[ c - 67 ];

// Takes a char 
c => 
    // Appends the input letter to...
    c + 

    // ... the name in the resulting index of the subtraction of the char with 67 ('C') if the char is uppercase ( 'C' == 67, 'O' == 79 )
    //    or with 99 ('c') if the char is lowercase ( 'c' == 99, 'o' == 111 )
    "upcake,onut,clair,royo,ingerbread,oneycomb,ce Cream Sandwich,ellybean,itkat,ollipop,arshmallow,ougat,reo"
        .Split( ',' )[ c - ( c < 99 ? 67 : 99 ) ];

完整代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TestBench {
    public static class Program {
        private static Func<Char, String> f = c =>
            c + "upcake,onut,clair,royo,ingerbread,oneycomb,ce Cream Sandwich,ellybean,itkat,ollipop,arshmallow,ougat,reo"
                .Split( ',' )[ c - 67 ];

        static void Main( string[] args ) {
            List<Char>
                testCases = new List<Char>() {
                    'C',
                    'D',
                    'E',
                    'F',
                    'G',
                    'H',
                    'I',
                    'J',
                    'K',
                    'L',
                    'M',
                    'N',
                    'O',
                };

            foreach(Char testCase in testCases) {
                Console.WriteLine($" Input: {testCase}\nOutput: {f(testCase)}\n");
            }

            Console.ReadLine();
        }
    }
}

发布

  • 1.0 - 147 bytes-初始溶液。
  • V1.1 - -11 bytes- 借用 奥利弗格雷的想法。
  • V1.2 - - 7 bytes-改变了功能,输入从显性到隐性。

笔记

  • 没有

您可以通过删除每个名称的第一个字母并将您从数组中检索到的字符串附加到输入字符来保存任何内容吗?
— 毛茸茸的

(char c)可能只是c
— LiefdeWen


1

Dyalog APL,125个字节

{⍵/⍨⍞=⎕A[+\⍵∊⎕A]}'ABCupcakeDonutEclairFroyoGingerbreadHonecombIce cream sandwichJellybeanKitkatLollipopMarshmallowNougatOreo'

在线尝试!

怎么样?

  • ⍵∊⎕A ⍵ (长字符串),其中1表示大写字母,0表示小写字母/空格。
  • +\ 用大写字母分组(返回数字)⍵。
  • ⎕A[...] 用数字表示的大写字母
  • ⍵/⍨⍞= 该数字表示的组
  • {...}'...'设置⍵为长字符串

聪明的方法。
— 亚当

1

R,131,126,123,112,178个字节

grep(paste0('^',scan(,'')),c("Cupcake","Donut","Eclair","Froyo","Gingerbread","Honeycomb","Ice Cream Sandwich","Jellybean","Kitkat","Lollipop","Marshmallow","Nougat","Oreo"),v=T)

感谢@Mark保存5 + 8 + 3个字节




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.