Skip to content

Commit

Permalink
Merge pull request #35 from AlgoLeadMe/10-pu2rile
Browse files Browse the repository at this point in the history
10-pu2rile
  • Loading branch information
pu2rile committed Jul 22, 2024
2 parents a4360da + 76a40d0 commit 4979c92
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 1 deletion.
Binary file added .DS_Store
Binary file not shown.
Binary file added pu2rile/.DS_Store
Binary file not shown.
3 changes: 2 additions & 1 deletion pu2rile/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
| 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)
| 9μ°¨μ‹œ | 2024.05.27 | κ΅¬ν˜„ | [μ˜€λŠ˜λ„ μ‘Œλ‹€](https://www.acmicpc.net/problem/14582) | [#29](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/29#issue-2320060288)
| 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) | [#35](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/35#issue-2403173169)
Binary file added pu2rile/μŠ€νƒ/.DS_Store
Binary file not shown.
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 4979c92

Please sign in to comment.