def calc(x
,c
,y
):
if c
=='+':
return x
+y
if c
=='-':
return x
-y
if c
=='*':
return x
*y
if c
=='/':
return x
/y
def isdigit(c
):
t
=ord(c
)
return t
>=ord('0') and t
<=ord('9')
comp
={'#':-1,'(':0,')':0,'+':1,'-':1,'*':2,'/':2}
op
=[]
op
.append
('#')
num
=[]
k
=input()
s
=[]
flag
=0
x
=0
for i
in range(len(k
)):
if isdigit
(k
[i
]):
x
=x
*10+int(k
[i
])
flag
=1
if not isdigit
(k
[i
]):
if flag
==1:
s
.append
(x
)
flag
=0
x
=0
s
.append
(k
[i
])
continue
if i
==len(k
)-1:
if flag
==1:
s
.append
(x
)
s
.append
('#')
for i
in range(len(s
)):
if type(s
[i
])==type(1):
num
.append
(s
[i
])
else:
if comp
[s
[i
]]>comp
[op
[-1]]:
op
.append
(s
[i
])
else:
if s
[i
]=='(':
op
.append
(s
[i
])
continue
if s
[i
]==')':
while op
[-1]!='(':
y
=num
.pop
()
x
=num
.pop
()
num
.append
(calc
(x
,op
.pop
(),y
))
op
.pop
()
else:
while comp
[s
[i
]]<=comp
[op
[-1]]:
if op
[-1]=='#':
break
y
=num
.pop
()
x
=num
.pop
()
num
.append
(calc
(x
,op
.pop
(),y
))
op
.append
(s
[i
])
print(num
[-1])
def move(cnt
,A
,B
,C
):
if cnt
==1:
print("%d %c %c"%(cnt
,A
,C
))
return
move
(cnt
-1,A
,C
,B
)
print("%d %c %c"%(cnt
,A
,C
))
move
(cnt
-1,B
,A
,C
)
n
=int(input())
move
(n
,'A','B','C')
转载请注明原文地址: https://lol.8miu.com/read-33104.html