complete 1918(후위 표기법)
This commit is contained in:
0
zeta_python/11726.py
Normal file
0
zeta_python/11726.py
Normal file
33
zeta_python/1485.py
Normal file
33
zeta_python/1485.py
Normal file
@@ -0,0 +1,33 @@
|
||||
N = int(input())
|
||||
|
||||
|
||||
def check90(p1, p2, p3):
|
||||
if p2[0] - p1[0] == 0:
|
||||
if p3[1] - p1[1] == 0:
|
||||
return True
|
||||
elif p3[0] - p1[0] == 0:
|
||||
if p2[1] - p1[1] == 0:
|
||||
return True
|
||||
|
||||
return - (p3[0] - p1[0]) * (p2[1] - p1[1]) == (p3[1] - p1[1]) * (p2[0] - p1[0])
|
||||
|
||||
|
||||
for _ in range(N):
|
||||
P = [(p1x, p1y), (p2x, p2y), (p3x, p3y), (p4x, p4y)] = \
|
||||
map(int, input().split()), map(int, input().split()), map(int, input().split()), map(int, input().split())
|
||||
if check90((p1x, p1y), (p2x, p2y), (p3x, p3y)):
|
||||
(opox, opoy) = p4x, p4y
|
||||
(remx, remy) = p3x, p3y
|
||||
elif check90((p1x, p1y), (p2x, p2y), (p4x, p4y)):
|
||||
(opox, opoy) = p3x, p3y
|
||||
(remx, remy) = p2x, p2y
|
||||
elif check90((p1x, p1y), (p3x, p3y), (p4x, p4y)):
|
||||
(opox, opoy) = p2x, p2y
|
||||
(remx, remy) = p4x, p4y
|
||||
else:
|
||||
print(0)
|
||||
continue
|
||||
if (opox - p1x) ** 2 + (opoy - p1y) ** 2 == 2 * (remx - p1x) ** 2 + 2 * (remy - p1y) ** 2:
|
||||
print(1)
|
||||
else:
|
||||
print(0)
|
||||
@@ -1,44 +0,0 @@
|
||||
import re
|
||||
OUT = []
|
||||
def turn_exp(start):
|
||||
t = start
|
||||
first = None
|
||||
second = None
|
||||
op = None
|
||||
if tokens[t].isalpha():
|
||||
first = tokens[t]
|
||||
t += 1
|
||||
elif tokens[t] == "(":
|
||||
rr = turn_exp(t+1)
|
||||
first = rr[1]
|
||||
t = rr[0]
|
||||
if tokens[t] == ")":
|
||||
t += 1
|
||||
if isinstance(first, str):
|
||||
OUT.append(first)
|
||||
if tokens[t] in "+-*/":
|
||||
op = tokens[t]
|
||||
t += 1
|
||||
|
||||
if tokens[t].isalpha():
|
||||
second = tokens[t]
|
||||
t += 1
|
||||
elif tokens[t] == "(":
|
||||
rr = turn_exp(t+1)
|
||||
second = rr[1]
|
||||
t = rr[0]
|
||||
if tokens[t] == ")":
|
||||
t += 1
|
||||
if isinstance(second, str):
|
||||
OUT.append(second)
|
||||
OUT.append(op)
|
||||
return t, [first, second, op]
|
||||
|
||||
tokens = input()
|
||||
|
||||
|
||||
|
||||
#_, parsed = turn_exp(0)
|
||||
#for o in OUT:
|
||||
#print(o, end = '')
|
||||
# TODO: 중위 표기식의 연산순서 A+B+C 같은거
|
||||
26
zeta_python/completed/1918.py
Normal file
26
zeta_python/completed/1918.py
Normal file
@@ -0,0 +1,26 @@
|
||||
I = input()
|
||||
stack = []
|
||||
priority = {"*": 3, "/": 3, "+": 2, "-": 2, "(": 1}
|
||||
for i in I:
|
||||
if i in "*/+-()":
|
||||
if len(stack) == 0:
|
||||
stack.append(i)
|
||||
continue
|
||||
if i == ")":
|
||||
while stack[-1] != "(":
|
||||
print(stack.pop(), end='')
|
||||
stack.pop()
|
||||
elif i == "(":
|
||||
stack.append(i)
|
||||
else:
|
||||
while priority[stack[-1]] >= priority[i]:
|
||||
print(stack.pop(), end='')
|
||||
if len(stack) == 0:
|
||||
break
|
||||
stack.append(i)
|
||||
|
||||
else:
|
||||
print(i, end='')
|
||||
else:
|
||||
for s in stack[::-1]:
|
||||
print(s, end='')
|
||||
Reference in New Issue
Block a user