Skip to content

Commit

Permalink
2024-07-11
Browse files Browse the repository at this point in the history
  • Loading branch information
pu2rile committed Jul 11, 2024
1 parent 3760ce9 commit 0988310
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pu2rile/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@
| 5μ°¨μ‹œ | 2024.04.10 | 그리디 μ•Œκ³ λ¦¬μ¦˜ | [κ΅­νšŒμ˜μ› μ„ κ±°](https://www.acmicpc.net/problem/1417) | [#18](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/18#issue-2235862658)
| 6μ°¨μ‹œ | 2024.05.10 | 그리디 μ•Œκ³ λ¦¬μ¦˜ | [ATM](https://www.acmicpc.net/problem/11399) | [#25](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/25#issue-2289086909)
| 7μ°¨μ‹œ | 2024.05.10 | μ™„μ „ 탐색 μ•Œκ³ λ¦¬μ¦˜ | [μ˜ν™”κ°λ… 숌](https://www.acmicpc.net/problem/1436) | [#26](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/25#issue-2289086909)
| 8μ°¨μ‹œ | 2024.05.14 | 그리디 μ•Œκ³ λ¦¬μ¦˜ | [νŒ”](https://www.acmicpc.net/problem/1105) | [#28](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/28#issue-2295901384)
| 8μ°¨μ‹œ | 2024.05.14 | 그리디 μ•Œκ³ λ¦¬μ¦˜ | [νŒ”](https://www.acmicpc.net/problem/1105) | [#28](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/28#issue-2295901384)
| 9μ°¨μ‹œ | 2024.05.27 | κ΅¬ν˜„ | [μ˜€λŠ˜λ„ μ‘Œλ‹€](https://www.acmicpc.net/problem/14582) | [#29](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/29#issue-2320060288)
| 10μ°¨μ‹œ | 2024.07.11 | μŠ€νƒ | [ν™”ν•™μ‹λŸ‰](https://www.acmicpc.net/problem/2257) | [#34]()
22 changes: 22 additions & 0 deletions pu2rile/μŠ€νƒ/ν™”ν•™μ‹λŸ‰.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
chemical = input()
stack = []
atomic = {'H':1, 'C':12, 'O':16} # μ›μžλŸ‰ λ”•μ…”λ„ˆλ¦¬

for c in chemical:
if c =='(':
stack.append(c)
elif c == 'H' or c == 'C' or c == 'O':
stack.append(atomic[c]) # μž…λ ₯받은 μ›μžμ˜ μ›μžλŸ‰μ„ μŠ€νƒμ— μΆ”κ°€
elif c == ')':
temp = 0 # λ‹«λŠ” κ΄„ν˜Έλ₯Ό λ§Œλ‚˜λ©΄ temp μ΄ˆκΈ°ν™”
while True:
if stack[-1] == '(': # μŠ€νƒμ˜ top이 μ—¬λŠ” κ΄„ν˜Έλ©΄
stack.pop() # μŠ€νƒμ—μ„œ μ—¬λŠ” κ΄„ν˜Έλ₯Ό μ‚­μ œ
stack.append(temp) # μŠ€νƒμ— temp μΆ”κ°€
break
else:
temp += stack.pop() # μ—¬λŠ” κ΄„ν˜Έ μ „κΉŒμ§€μ˜ μŠ€νƒ μ•ˆμ˜ λͺ¨λ“  값을 temp에 μ €μž₯
else: # cκ°€ 숫자라면
stack.append(stack.pop()*int(c)) # μŠ€νƒμ˜ top κ°’κ³Ό 숫자λ₯Ό κ³±ν•˜μ—¬ μŠ€νƒμ— μΆ”κ°€

print(sum(stack))

0 comments on commit 0988310

Please sign in to comment.