Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4-pu2rile #15

Merged
merged 2 commits into from
Jul 3, 2024
Merged

4-pu2rile #15

merged 2 commits into from
Jul 3, 2024

Conversation

pu2rile
Copy link
Collaborator

@pu2rile pu2rile commented Apr 7, 2024

๐Ÿ”— ๋ฌธ์ œ ๋งํฌ

https://www.acmicpc.net/problem/10773

โœ”๏ธ ์†Œ์š”๋œ ์‹œ๊ฐ„

10๋ถ„

โœจ ์ˆ˜๋„ ์ฝ”๋“œ

  1. pushํ•  ๋งŒํผ์˜ ์ˆ˜๋ฅผ k๋กœ ์ž…๋ ฅ๋ฐ›์Œ
  2. ์Šคํƒ์— n์„ push
  3. 0์ด ์ž…๋ ฅ๋˜๋ฉด pop ํ•˜๋Š” ์กฐ๊ฑด ์ ์šฉ
    3-1. 0์ด ์•„๋‹ˆ๋ผ๋ฉด ๊ทธ๋Œ€๋กœ push
  4. sumํ•จ์ˆ˜๋ฅผ ์ด์šฉํ•˜์—ฌ ๋ฆฌ์ŠคํŠธ ์š”์†Œ ๋”ํ•˜๊ธฐ

๐Ÿ–ฅ๏ธ ์ฝ”๋“œ

k = int(input())
stack = []
for _ in range(k):
  n = int(input())
  if n == 0:
    stack.pop()
  else:
    stack.append(n)
print(sum(stack))

๐Ÿ“š ์ƒˆ๋กญ๊ฒŒ ์•Œ๊ฒŒ๋œ ๋‚ด์šฉ

์ž๋ฃŒ๊ตฌ์กฐ๋ฅผ c์—์„œ๋งŒ ๋‹ค๋ค„ ๋ด์„œ ์ด๋ฒˆ ๊ธฐํšŒ์— ํŒŒ์ด์ฌ์œผ๋กœ๋„ ๊ณต๋ถ€ํ•ด ๋ณด๊ณ ์ž ์ฒซ ๋‹จ๊ณ„์ธ ์Šคํƒ ๋ฌธ์ œ๋ถ€ํ„ฐ ํ’€์–ด๋ดค์–ด์š”...
ํŒŒ์ด์ฌ์—์„œ ๋”ฐ๋กœ ์‚ฌ์šฉํ•˜๋Š” ํ•จ์ˆ˜๊ฐ€ ์žˆ๋‚˜ ์‹ถ์–ด ๊ฒ€์ƒ‰ํ•˜์—ฌ ์‚ฌ์šฉํ–ˆ์Šต๋‹ˆ๋‹ค! ์ฐธ๊ณ ํ•œ ๋ธ”๋กœ๊ทธ
๋‹ค์Œ pr์—์„œ๋Š” ํ ๋ฌธ์ œ๋ฅผ ํ’€์–ด๋ด์•ผ๊ฒ ์–ด์š”!!

Copy link
Collaborator

@suhyun113 suhyun113 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์Šคํƒ ์œ ํ˜•์€ ์ €๋ฒˆ์—๋„ ๋ณธ ์ ์ด ์žˆ์–ด์„œ ์›๋ฆฌ๋ฅผ ์กฐ๊ธˆ ์•Œ๊ณ  ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค. ๊ทธ๋ž˜์„œ ์ฝ”๋“œ๋ฅผ ๋น„๊ต์  ์‰ฝ๊ฒŒ ์ดํ•ดํ•  ์ˆ˜ ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค. ์ €๋Š” ๋จผ์ € ์ด ๋ฌธ์ œ๋ฅผ ์ดํ•ดํ•˜๊ธฐ ์œ„ํ•ด ์˜ˆ์‹œ๋ฅผ ์ด์šฉํ•ด ์ง์ ‘ ์Šคํƒ์— ์Œ“๊ณ  ๋นผ๋‚˜๊ฐ€๋Š” ๊ณผ์ •์„ ๊ทธ๋ฆผ์œผ๋กœ ํ‘œํ˜„ํ•˜์˜€์Šต๋‹ˆ๋‹ค.





์œ„์˜ ์‚ฌ์ง„์ฒ˜๋Ÿผ ๋‘ ๊ฐ€์ง€ ์˜ˆ์‹œ๋ฅผ ๊ทธ๋ ค๋ณด๋ฉฐ ์ดํ•ดํ•œ ํ›„, ์ด ์ฝ”๋“œ๋ฅผ ์งœ๋Š” ๋ฐ์— ํ•„์š”ํ•œ ๊ฒƒ์„ ์ƒ๊ฐํ•ด๋ณด์•˜์Šต๋‹ˆ๋‹ค. ๋„ํ˜„๋‹˜์ด ์„ค๋ช…ํ•ด์ฃผ์‹  ๊ฒƒ์ฒ˜๋Ÿผ ์ €๋„ ์ƒ๊ฐํ•˜์—ฌ ์ด ๋ฌธ์ œ๋ฅผ ์ž˜ ํ’€๊ณ  ์ดํ•ดํ•  ์ˆ˜ ์žˆ์—ˆ์–ด์š”!
๋‹ค์Œ PR์€ ์Šคํƒ ๋ฌธ์ œ๋ฅผ ํ•ด๋ด์•ผ๊ฒ ์–ด์š”~
4๋ฒˆ์งธ PR ์ˆ˜๊ณ ํ•˜์…จ์Šต๋‹ˆ๋‹น

Copy link
Member

@oesnuj oesnuj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๊น”๋” ๊ฐ„๋‹จํ•˜๊ฒŒ ์Šคํƒ๋ฌธ์ œ๋ฅผ ํ‘ธ์…จ๋„ค์š”!!
ํŒŒ์ด์ฌ ์Šคํƒ ์‚ฌ์šฉ๋ฒ•์„ ์•Œ์•„๊ฐ‘๋‹ˆ๋‹ค
PR ์ˆ˜๊ณ ํ•˜์…จ์–ด์š”๐Ÿ‘๐Ÿ‘

@Ghdrn1399
Copy link
Contributor

์˜ค.. ์ €๋„ ์ฃผ๋กœ c๋กœ๋งŒ ์ž๋ฃŒ๊ตฌ์กฐ๋ฅผ ๋‹ค๋ค„๋ณด๋‹ค๊ฐ€ ํŒŒ์ด์ฌ๋„ ๊ณต๋ถ€ํ•ด ๋ณด๊ณ ์‹ถ์—ˆ๋Š”๋ฐ ๋•๋ถ„์— ์Šคํƒ ์‚ฌ์šฉ๋ฒ•์„ ์ž˜ ์•Œ์•„๊ฐ€๋„ค์š” ใ…Žใ…Ž
์ฝ”๋“œ๋„ ๊ฐ„๊ฒฐํ•ด์„œ ์ž˜ ๋ดค์Šต๋‹ˆ๋‹ค!! ๋ธ”๋กœ๊ทธ ๋งํฌ ๋‹ฌ์•„์ฃผ์‹ ๊ฒƒ๋„ ํ•œ๋ฒˆ ์ฝ์–ด๋ณผ๊ฒŒ์š” ใ…Žใ…Ž

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants