Answers:
感谢@daHugLenny和@Adnan 1个字节!
感谢@Emigna 1个字节!
[IDõQiX,ëU
®
和,则不需要反斜杠。©
X
U
for(;;b?a=b:alert(a))b=prompt()
无限循环不断要求输入并将其存储在中b
。如果输入不为空,则将其存储在中a
,否则将输出的值a
。
@ETHproductions节省了2个字节
1
,并通过移至b?a=b:alert(a)
for循环的最后一部分(即for(a=0;;b?a=b:alert(a))b=prompt()
)保存一个字节
a=0
也没有必要。由于只有在存储了问题的情况下,输入才可以为空,因此,a
如果未分配输入,则不会引用该输入。
id""E[$dp]~*
id""E[$dp]~*
i take a line of input [input]
d""E push equality with "" [input, input == ""]
[$dp] push that func [input, input == "", [$p]]
~* execute it iff equal
on equal:
$ drop empty input
dp duplicate then print the TOS
this wraps around to the beginning, taking another line of input
q=[]
while 1:
s=input()
if''<s:q+=[s]
else:print(q.pop())
a←⍞⋄→(0=⍴a)/1⋄a⋄→1
⍝ Note: the ⋄ symbols are statement separators, so I've replaced them here with newlines
a←⍞ ⍝ get an input string (⍞) and store it in variable a
→(0=⍴a)/1 ⍝ if the length of a (⍴a) is 0, goto (→) the start of this program (1)
a ⍝ else, print a
→1 ⍝ goto the start of the program (1)
class M{public static void main(String[]a){String s="",x;do{x=new java.util.Scanner(System.in).nextLine();if(x.isEmpty())System.out.println(s);else s=x;}while(1>0);}}
通过@cliffroot可以new java.util.Scanner
直接使用-9个字节。
可能是我第一次do-while
在代码高尔夫挑战赛中使用a 。
当允许使用函数而不是程序时,它为135个字节(仍然比大多数其他答案高很多倍。)
void c(){for(String s="",x;(x=new java.util.Scanner(System.in).nextLine())!=null;)if(x.isEmpty())System.out.println(s);else s=x;}
for
还是while
某处吗?..什么是(x=new java.util.Scanner(System.in).nextLine())!=null;)
?
void c(){for(String s="",x;for(x=new java.util.Scanner(System.in).nextLine())!=null;)if(x.isEmpty())System.out.println(s);else s=x;}
,实际上比它的版本长了1个字节do-while
–void c(){String s="",x;do{x=new java.util.Scanner(System.in).nextLine();if(x.isEmpty())System.out.println(s);else s=x;}while(1>0);}
/./{x;d};g
说明:
(implicit at start of program) read input, overwriting old input
/./{ If the input is nonempty
x; swap the input with the hold space
d then restart, without any implicit printing of input
}; end if statement
g Append the hold space to the [empty] input
(implicit at end of program) print the input, then restart
很高兴看到一种外在的(即“非深奥的”)语言与某些高尔夫语言联系在一起!