编写一个程序,接受一个表情符号作为输入,如果表情符号是快乐的或悲伤的,则输出它。
程序接受字符串作为输入或参数,如果输入在快乐表情列表中,则应该显示字符串“高兴”;如果输入在悲伤表情列表中,则应该显示“悲伤”。
您可以假设输入始终是有效的(高兴或悲伤)表情,周围没有空格或选项卡。
下面是一个空格分隔的快乐表情列表:
:-) :) :D :o) :] :3 :c) :> =] 8) =) :} :^) :-D 8-D 8D x-D xD X-D XD =-D =D =-3 =3 B^D (-: (: (o: [: <: [= (8 (= {: (^:下面是一个空格分隔的悲伤表情列表:
>:[ :-( :( :-c :c :-< :< :-[ :[ :{ 8( 8-( ]:< )-: ): >-: >: ]-: ]: }: )8 )-8这是密码-高尔夫,所以最短的节目获胜。
发布于 2015-09-12 13:07:00
(rh{,"[(c<{":Im?};?h{,"])>}":Im?}),"sad".;"happy".( ),"sad".;"happy". § If what's in the parentheses is true,
§ output "sad", else output "happy".
rhA § Unify A with the last char of the input
,"[(c<{":ImA § True if A is a char of "[(c<{"
; § OR
?hA § Unify A with the first char of the input
,"])>}":ImA § True if A is a char of "])>}"发布于 2015-09-12 10:43:52
i,e=raw_input(),0
for c in i:e=(e,i.index(c))[c in":=8xXB"]
f,s,h=i[:e],i[e+1:],0
for c in f:h+=c in"[(c<{"
for c in s:h+=c in")]}>D"
print["Sad","Happy"][h>0]https://codegolf.stackexchange.com/questions/57753
复制相似问题