最近,一位研究交通灯计时的电气工程师是俄勒冈州罚款500美元,因为他自称是一名工程师。
给定一个两个字母字符串作为输入,表示一个美国状态,输出:
I am not an engineer如果该州是俄勒冈州(OR)I am an engineerWhat is an engineer?输出可能不包含任何前导空格,但可能包含任意多的尾随空格。
您可以假设输入总是2个大写字母。
以下是所有50个美国州缩略语的列表:
AL, AK, AZ, AR, CA, CO, CT, DE, FL, GA, HI, ID, IL, IN, IA, KS, KY, LA, ME,
MD, MA, MI, MN, MS, MO, MT, NE, NV, NH, NJ, NM, NY, NC, ND, OH, OK, OR, PA,
RI, SC, SD, TN, TX, UT, VT, VA, WA, WV, WI, WY这是密码-高尔夫,所以在每种语言中最少的字节获胜!
发布于 2017-06-02 13:18:18
s->s.format(s.equals("OR")?"I am not%s":"MINCALA MSCTNMNVAKY WAZ PAR FL GA NHID COKSD ME MDE MA MTX NE NJ NY ND MOH RIA UT WVT WIL WY".contains(s)?"I am%s":"What is%s?"," an engineer")我很抱歉重用了压缩的字符串:我一个人找不到更好的.:(
发布于 2017-06-02 14:27:03
"ORIA MINCALA MSCTNMNVAKY WAZ PAR FL GA NHID COKSD ME MDE MA MTX NE NJ NY ND MOH UT WVT WIL WY"q#g"I am not
I am
What is?"N/=)" an engineer"\"ORIA...." e# Push a string in which every state is a substring, but no non-state is
e# a substring.
q e# Read the input.
# e# Find the index of the input in the string. (-1 if not found)
g e# Signum of the index: -1 for negative, 0 for 0, 1 for positive.
"I am.... " e# Push this string. Note the trailing space on the first two lines of it.
N/ e# Split it on newlines.
= e# Get the string at index given by the signum.
) e# Pull out the last character.
" an engineer"\ e# Push " an engineer" and bring the other character to the TOS.
e# Implicit output.由于俄勒冈州(OR)位于字符串的开头,因此在该字符串中找到输入索引的符号是-1 (如果没有找到)、0(如果是OR )、1(如果有其他状态)。要打印的字符串可以由该字符串来决定。
发布于 2017-06-02 20:23:06
s=>(s=="OR"?"I am notx":"MINCALA MSCTNMNVAKY WAZ PARIA FL GA NHID COKSD ME MDE MA MTX NE NJ NY ND MOH UT WVT WIL WY".Contains(s)?"I amx":"What isx?").Replace("x"," an engineer");在C# Pad中运行
高尔夫基于梅尤贝解;新的这里,所以我没有足够的代表来评论。
https://codegolf.stackexchange.com/questions/124145
复制相似问题