CJam,130字节
LqY5m*{"lemon"_eu}%3/:z{~?}f%{_@\/_:,[{1$+}*]);@f{[\]}@+\1a*}/\{1
=}$0f=\1$,{"ade"{__C#)\Ceu#)|(\0+We\)@_N=@+N\t\}fC}fN0a/L*1a/\.{}
为了清楚起见,将其分为两行。换行符不计算在内。
伪代码:
FLAG_1 = object()
FLAG_2 = object()
lemon_instances = [] # CJam: L
input_chars = list(all_input()) # CJam: q
lemons = [
"LEMON", "LEMOn", "LEMoN", "LEMon", "LEmON", "LEmOn", "LEmoN", "LEmon",
"LeMON", "LeMOn", "LeMoN", "LeMon", "LemON", "LemOn", "LemoN", "Lemon",
"lEMON", "lEMOn", "lEMoN", "lEMon", "lEmON", "lEmOn", "lEmoN", "lEmon",
"leMON", "leMOn", "leMoN", "leMon", "lemON", "lemOn", "lemoN", "lemon"
] # CJam: Y5m*{"lemon"_eu}%3/:z{~?}f%
for i in lemons: # CJam: { ... }/
temp = input_chars.split(i) # CJam: _@\/
lengths = temp.map(len) # CJam: _:,
# Here, accum turns an array like [1,2,3] into [1,3,6].
indices = accum(lengths) # CJam: [{1$+}*]
indices.pop() # CJam: );
temp2 = zip(temp, indices) # CJam: @f{[\]}
lemon_instances = temp2 + lemon_instances # CJam: @+
input_chars = join_array(temp, FLAG_1) # CJam: 1a*
lemon_instances.sort(key=lambda x: x[1]) # CJam: {1=}$
lemon_instances = [i[0] for i in lemon_instances] # CJam: 0f=
for i in range(len(lemon_instances)): # CJam: \1$,{...}fN
for c in "ade": # CJam: "ade"{...}fC
# list_index returns -1 if not found
lower = list_index(input_chars, c)+1 # CJam: __C#)
upper = list_index(input_chars, upper(c))+1 # CJam: \Ceu#)
char_index = (lower or upper) - 1 # CJam: |(
input_chars.append(FLAG_2) # CJam: \0+
# -1 refers to the last element in the list
swap_list_elements(input_chars, char_index, -1) # CJam: e\
extracted = input_chars.pop() # CJam: )
lemon_instances[i] += extracted # CJam: @_N=@+N\t\
remove_all(input_chars, FLAG_2) # CJam: 0a/L*
temp1 = input_chars.split(FLAG_1) # CJam: 1a/
# interleave([1, 2, 3], ["a", "b"]) gives [1, "a", 2, "b", 3]
temp2 = interleave(temp1, lemon_instances) # CJam: \.{}
print("".join(temp2))
e
,a
或者d
就是你必须输出是什么做的,能与给定的字母。例如输入bdblemon
将输出bblemond
”)?