将语言中的某些代码作为字符串,查找并显示所有变量名称。
伪码的例子:
a=2
b=3
for(i, 0->9) do b=b-10
if a=b then write "a equals b"返回:a b i
abcdefgh=20000000000000
bcdifhgs="hello"
if abcdefgh=bcdifhgs then da44="hax"
if abcdefgh*2=da44 then write da44返回:abcdefgh bcdifhgs da44
2=3
3=5
5=7
if 2=7 then exit返回:
a=2
while True do b=3返回:a b
最短代码获胜。
对于基于堆栈的语言,显示堆栈的最高高度。
对于基于内存单元格的语言,显示已更改的所有内存单元格。
发布于 2012-08-09 18:57:02
[]只有当你用“变量”这个词的字面意思。
发布于 2012-08-10 00:51:44
import sys,re,keyword
print(set(re.findall(r"\b\w+\b",sys.argv[1]))-set(keyword.kwlist+dir(__builtins__)))发布于 2012-08-22 20:54:09
Python,111
我对高尔夫很陌生.小贴士很受欢迎,但这里有另一种方法
import ast as a
s=set()
v=a.NodeVisitor
v.visit_Name=lambda t,n:s.add(n.id)
v().visit(a.parse(input()))
print shttps://codegolf.stackexchange.com/questions/6942
复制相似问题