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

12-2secondag #58

Merged
merged 2 commits into from
Feb 19, 2024
Merged

12-2secondag #58

merged 2 commits into from
Feb 19, 2024

Conversation

2secondag
Copy link
Collaborator

@2secondag 2secondag commented Feb 15, 2024

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

์Šคํƒ

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

1์‹œ๊ฐ„ ๋ฐ˜

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

โ“๋ฌธ์ œ ์„ค๋ช…

์ฒซ์งธ ์ค„์— N๊ฐœ์˜ ๋ช…๋ น์˜ ์ˆ˜๊ฐ€ ์ฃผ์–ด์ง€๊ณ  ๋ช…๋ น์—๋Š” ์ด ๋‹ค์„ฏ ๊ฐ€์ง€๊ฐ€ ์žˆ๋‹ค.

image

โ“๊ฐ„๋‹จํ•œ ๊ฐœ๋… ์„ค๋ช…

์Šคํƒ์ด๋ž€?
๊ฐ€์žฅ ๋‚˜์ค‘์— ๋“ค์–ด์˜จ ์ž๋ฃŒ๊ฐ€ ๊ฐ€์žฅ ๋จผ์ € ์ฒ˜๋ฆฌ๋˜๋Š” ์ž๋ฃŒ๊ตฌ์กฐ์ด๋‹ค. ( Last In First Out )
image

โ“ ์ฝ”๋“œ ์„ค๋ช…

sen = list(map(str, sys.stdin.readline().split()))

  if sen[0] == "push":
    stack.append(int(sen[1]))

  elif sen[0] == "pop":
    if len(stack) > 0:
      print(stack[-1])
      stack.pop()
    else:
      print(-1)
  • ์‹œ๊ฐ„์„ ์ค„์ด๊ธฐ ์œ„ํ•ด์„œ sys.stdin.readline()์„ ์‚ฌ์šฉํ•˜์—ฌ ๋ฐฐ์—ด๋กœ ์ž…๋ ฅ๋ฐ›์€ ํ›„ ๋ฐฐ์—ด์˜ ์ฒซ๋ฒˆ์งธ ์š”์†Œ์— ๋”ฐ๋ผ์„œ ๊ฐ ๋ช…๋ น์— ํ•ด๋‹นํ•˜๋Š” ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•˜๋ฉด ๋œ๋‹ค.

  • ** push์˜ ๊ฒฝ์šฐ**
    ๋ฆฌ์ŠคํŠธ์— strํ˜•ํƒœ๋กœ ์ €์žฅ๋œ ๋ฌธ์ž๋ฅผ intํ˜•์œผ๋กœ ๋ฐ”๊ฟ”์ค€ ๋’ค, ์Šคํƒ์— ์ €์žฅํ•œ๋‹ค.

  • ** pop์˜ ๊ฒฝ์šฐ**
    ์Šคํƒ์— ๋“ค์–ด์žˆ๋Š” ์ •์ˆ˜๊ฐ€ ์žˆ๋Š” ๊ฒฝ์šฐ์™€ ์—†๋Š” ๊ฒฝ์šฐ๋กœ ๋‚˜๋ˆ„์–ด ๋ช…๋ น์„ ์ˆ˜ํ–‰ํ•œ๋‹ค.

elif sen[0] == "size":
    print(len(stack))

  elif sen[0] == "empty":
    if len(stack) > 0:
      print(0)
    else: 
      print(1)
  • size์˜ ๊ฒฝ์šฐ
    stack.size()๋ฅผ ์‚ฌ์šฉํ•˜๋ ค๊ณ  ํ•˜์˜€์œผ๋‚˜ ํŒŒ์ด์ฌ์—์„œ ์Šคํƒ์„ ๋ฆฌ์ŠคํŠธ๋กœ ๊ตฌํ˜„ํ•˜๋Š”๋ฐ ๋ฆฌ์ŠคํŠธ์—๋Š” '.size()' ๊ฐ€ ์—†๊ธฐ ๋•Œ๋ฌธ์— ๊ธธ์ด๋ฅผ ์•Œ ์ˆ˜ ์žˆ๋Š” len()์„ ์‚ฌ์šฉํ•˜์—ฌ ์Šคํƒ์— ๋“ค์–ด์žˆ๋Š” ์ •์ˆ˜์˜ ๊ฐœ์ˆ˜๋ฅผ ์ถœ๋ ฅํ–ˆ๋‹ค.

  • empty์˜ ๊ฒฝ์šฐ
    ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ len()์„ ์‚ฌ์šฉํ•˜์—ฌ ์Šคํƒ์ด ๋น„์–ด์žˆ๋Š”์ง€ ํ™•์ธํ•œ๋‹ค.

 elif sen[0] == "top":
    if len(stack)>0 :
      print(stack[-1])
    else:
      print(-1)
  • top์˜ ๊ฒฝ์šฐ
    len()์„ ์‚ฌ์šฉํ•œ ๊ฒƒ๊ณผ ๊ฐ™์€ ๋งฅ๋ฝ์œผ๋กœ ์Šคํƒ์„ ๋ฆฌ์ŠคํŠธ๋กœ ๊ตฌํ˜„ํ•˜์—ฌ stack.peek()์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†๊ธฐ ๋•Œ๋ฌธ์— `stack[-1]'์„ ์‚ฌ์šฉํ•˜์—ฌ ๊ฐ€์žฅ ๋งˆ์ง€๋ง‰ ์š”์†Œ๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค.

โ“ ์ „์ฒด์ฝ”๋“œ

import sys

N = int(sys.stdin.readline())
stack = []

for i in range (N):
  sen = list(map(str, sys.stdin.readline().split()))

  if sen[0] == "push":
    stack.append(int(sen[1]))

  elif sen[0] == "pop":
    if len(stack) > 0:
      print(stack[-1])
      stack.pop()
    else:
      print(-1)

  elif sen[0] == "size":
    print(len(stack))

  elif sen[0] == "empty":
    if len(stack) > 0:
      print(0)
    else: 
      print(1)

  elif sen[0] == "top":
    if len(stack)>0 :
      print(stack[-1])
    else:
      print(-1)

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

์Šคํƒ ๋ฌธ๋ฒ• ์ฐธ๊ณ 
ํŒŒ์ด์ฌ ์ž…๋ ฅ ์‹œ๊ฐ„ ๋‹จ์ถ• ๋ฐฉ๋ฒ•

  • ๋ฐ˜๋ณต๋ฌธ์œผ๋กœ ์—ฌ๋Ÿฌ์ค„์„ ์ž…๋ ฅ ๋ฐ›์•„์•ผ ํ•˜๋Š” ๊ฒฝ์šฐ์— input()์œผ๋กœ ์ž…๋ ฅ๋ฐ›๊ฒŒ ๋œ๋‹ค๋ฉด ์‹œ๊ฐ„ ์ดˆ๊ณผ๊ฐ€ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ๋‹ค.

ํ•ด๊ฒฐ ๋ฐฉ์•ˆ => sys.stdlin.readline() ๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ!

! ์ฃผ์˜ํ•  ์  !

import sys
a =  sys.stdin.readline()

sys.stdin.readline()๋Š” ํ•œ ์ค„ ๋‹จ์œ„๋กœ ์ž…๋ ฅ๋ฐ›๊ธฐ ๋•Œ๋ฌธ์— ๊ฐœํ–‰ ๋ฌธ์ž๊ฐ€ ๊ฐ™์ด ์ž…๋ ฅ ๋ฐ›์•„์ง€๋Š” ๊ฒฝ์šฐ๊ฐ€ ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค. ๋˜ํ•œ ๋ณ€์ˆ˜ ํƒ€์ž…์ด str๋กœ ์ €์žฅ๋˜๊ธฐ ๋•Œ๋ฌธ์— ํ˜•๋ณ‘ํ™˜์„ ๊ฑฐ์น˜๋Š” ์ž‘์—…์ด ํ•„์š”ํ•˜๋‹ค!

-> ์ˆ˜์ •๋œ ์ฝ”๋“œ

import sys
a =  int(sys.stdin.readline())

๐Ÿ“š ๊ถ๊ธˆํ•œ ์ 

stack = []
N = int(input())

for i in range (N):
  sen = str(input().split())
  print(sen)

  if sen[0] == 'push':
    print("push ๋ธ”๋ก ์‹คํ–‰ ํ™•์ธ")
    stack.append(int(sen[1]))
    
  print(stack)

์ฒ˜์Œ์— ์ œ๊ฐ€ ์ž‘์„ฑํ•œ ์ฝ”๋“œ์ธ๋ฐ, push 1์„ ์ž…๋ ฅํ–ˆ์„ ๋•Œ if sen == "push":๋ฌธ์ด ์‹คํ–‰์ด ์•ˆ๋˜๋Š”๋ฐ ์™œ ์•ˆ ๋˜๋Š” ๊ฑธ๊นŒ์š”?!
image

์ฑ—gpt๋ฅผ ๋Œ๋ ค ์ •์ƒ์ž‘๋™ํ•˜๋Š” ์ฝ”๋“œ์ธ๋ฐ์š”...

stack = []
N = int(input())

for i in range(N):
    input_str = input().split()  # ์ž…๋ ฅ ๋ฌธ์ž์—ด์„ ๊ณต๋ฐฑ์„ ๊ธฐ์ค€์œผ๋กœ ๋ถ„๋ฆฌ

    if input_str[0] == "push":
        print("push ๋ธ”๋ก ์‹คํ–‰ ํ™•์ธ")
        num = int(input_str[1])  # ์ˆซ์ž ๋ถ€๋ถ„์„ ์ถ”์ถœ
        stack.append(num)

    print(stack)

image

####๊ฒฐ๋ก !!!
sen = str(input().split()) ์™€ input_str = input().split()์˜ ์ฐจ์ด๊ฐ€ ๋ญ˜๊นŒ์šœ.....?!

@9kyo-hwang
Copy link

1๋ฒˆ ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค์— ๋Œ€ํ•ด ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ฝ”๋“œ๋ฅผ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

for _ in range(int(input())):
    sen = input().split()
    print(type(sen), sen)

์ถœ๋ ฅ์€ ๋‹ค์Œ๊ณผ ๊ฐ™๊ตฌ์š”.

<class 'list'> ['push', '1']
<class 'list'> ['push', '2']
<class 'list'> ['top']
<class 'list'> ['size']
<class 'list'> ['empty']
<class 'list'> ['pop']
<class 'list'> ['pop']
<class 'list'> ['pop']
<class 'list'> ['size']
<class 'list'> ['empty']
<class 'list'> ['pop']
<class 'list'> ['push', '3']
<class 'list'> ['empty']
<class 'list'> ['top']

๊ฐ๊ฐ์˜ sen์€ ๋ฌธ์ž์—ด์„ ๋‹ด๊ณ  ์žˆ๋Š” "๋ฆฌ์ŠคํŠธ" ํƒ€์ž…์ธ ๊ฒƒ์„ ์•Œ ์ˆ˜ ์žˆ์ฃ ? ๊ทธ๋ž˜์„œ sen[0] == 'push'์™€ ๊ฐ™์ด ์ธ๋ฑ์Šค๋ฅผ ์ด์šฉํ•ด ์›์†Œ๋ฅผ ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๋Š” ๊ฑฐ๊ตฌ์š”.

ํ•œ ๋ฒˆ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๋ณ€๊ฒฝํ•ด๋ณผ๊นŒ์š”?

for _ in range(int(input())):
    sen = str(input().split())  # string์œผ๋กœ ํƒ€์ž… ์บ์ŠคํŒ…
    print(type(sen), sen)
<class 'str'> ['push', '1']
<class 'str'> ['push', '2']
<class 'str'> ['top']
<class 'str'> ['size']
<class 'str'> ['empty']
<class 'str'> ['pop']
<class 'str'> ['pop']
<class 'str'> ['pop']
<class 'str'> ['size']
<class 'str'> ['empty']
<class 'str'> ['pop']
<class 'str'> ['push', '3']
<class 'str'> ['empty']
<class 'str'> ['top']

์ƒ๊ธด๊ฑด ๋˜‘๊ฐ™์ง€๋งŒ, ๊ฐ๊ฐ์˜ sen์ด ๋ฌธ์ž์—ด๋กœ ๋ณ€๊ฒฝ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ['push', '1']๋ฅผ ์ข€ ๋” ์ž์„ธํžˆ ํ™•์ธํ•ด๋ณผ๊นŒ์š”?

for _ in range(int(input())):
    sen = str(input().split())
    print(type(sen), sen)
    for ch in sen:
        print(ch)
<class 'str'> ['push', '1']
[
'
p
u
s
h
'
,
 
'
1
'
]

์ฆ‰ ['push', '1']์ด ์ƒ๊น€์ƒˆ ๊ทธ๋Œ€๋กœ ๋ฌธ์ž์—ด๋กœ ๋ณ€๊ฒฝ๋œ ๊ฒƒ์„ ์•Œ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋Œ€๊ด„ํ˜ธ([])์กฐ์ฐจ '๋ฌธ์ž'์ธ ๊ฒƒ์ด์ฃ .
๊ทธ๋ ‡๊ธฐ ๋•Œ๋ฌธ์— ์œ„ ์˜ˆ์‹œ์˜ ๊ฒฝ์šฐ sen[0] == '['์ธ ๊ฒƒ์ž…๋‹ˆ๋‹ค. ๋ฆฌ์ŠคํŠธ์ฒ˜๋Ÿผ 'push'๊ฐ€ ์•„๋‹Œ ๊ฑฐ์ฃ .

@2secondag
Copy link
Collaborator Author

2secondag commented Feb 17, 2024

1๋ฒˆ ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค์— ๋Œ€ํ•ด ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ฝ”๋“œ๋ฅผ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

for _ in range(int(input())):
    sen = input().split()
    print(type(sen), sen)

์ถœ๋ ฅ์€ ๋‹ค์Œ๊ณผ ๊ฐ™๊ตฌ์š”.

<class 'list'> ['push', '1']
<class 'list'> ['push', '2']
<class 'list'> ['top']
<class 'list'> ['size']
<class 'list'> ['empty']
<class 'list'> ['pop']
<class 'list'> ['pop']
<class 'list'> ['pop']
<class 'list'> ['size']
<class 'list'> ['empty']
<class 'list'> ['pop']
<class 'list'> ['push', '3']
<class 'list'> ['empty']
<class 'list'> ['top']

๊ฐ๊ฐ์˜ sen์€ ๋ฌธ์ž์—ด์„ ๋‹ด๊ณ  ์žˆ๋Š” "๋ฆฌ์ŠคํŠธ" ํƒ€์ž…์ธ ๊ฒƒ์„ ์•Œ ์ˆ˜ ์žˆ์ฃ ? ๊ทธ๋ž˜์„œ sen[0] == 'push'์™€ ๊ฐ™์ด ์ธ๋ฑ์Šค๋ฅผ ์ด์šฉํ•ด ์›์†Œ๋ฅผ ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๋Š” ๊ฑฐ๊ตฌ์š”.

ํ•œ ๋ฒˆ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๋ณ€๊ฒฝํ•ด๋ณผ๊นŒ์š”?

for _ in range(int(input())):
    sen = str(input().split())  # string์œผ๋กœ ํƒ€์ž… ์บ์ŠคํŒ…
    print(type(sen), sen)
<class 'str'> ['push', '1']
<class 'str'> ['push', '2']
<class 'str'> ['top']
<class 'str'> ['size']
<class 'str'> ['empty']
<class 'str'> ['pop']
<class 'str'> ['pop']
<class 'str'> ['pop']
<class 'str'> ['size']
<class 'str'> ['empty']
<class 'str'> ['pop']
<class 'str'> ['push', '3']
<class 'str'> ['empty']
<class 'str'> ['top']

์ƒ๊ธด๊ฑด ๋˜‘๊ฐ™์ง€๋งŒ, ๊ฐ๊ฐ์˜ sen์ด ๋ฌธ์ž์—ด๋กœ ๋ณ€๊ฒฝ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ['push', '1']๋ฅผ ์ข€ ๋” ์ž์„ธํžˆ ํ™•์ธํ•ด๋ณผ๊นŒ์š”?

for _ in range(int(input())):
    sen = str(input().split())
    print(type(sen), sen)
    for ch in sen:
        print(ch)
<class 'str'> ['push', '1']
[
'
p
u
s
h
'
,
 
'
1
'
]

์ฆ‰ ['push', '1']์ด ์ƒ๊น€์ƒˆ ๊ทธ๋Œ€๋กœ ๋ฌธ์ž์—ด๋กœ ๋ณ€๊ฒฝ๋œ ๊ฒƒ์„ ์•Œ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋Œ€๊ด„ํ˜ธ([])์กฐ์ฐจ '๋ฌธ์ž'์ธ ๊ฒƒ์ด์ฃ . ๊ทธ๋ ‡๊ธฐ ๋•Œ๋ฌธ์— ์œ„ ์˜ˆ์‹œ์˜ ๊ฒฝ์šฐ sen[0] == '['์ธ ๊ฒƒ์ž…๋‹ˆ๋‹ค. ๋ฆฌ์ŠคํŠธ์ฒ˜๋Ÿผ 'push'๊ฐ€ ์•„๋‹Œ ๊ฑฐ์ฃ .

์™€์šฐ. ์นœ์ ˆํ•œ ๋‹ต๋ณ€ ์•„์ฃผ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค. ์™„์ „ ์ดํ•ดํ–ˆ์–ด์š”.

@miniron-v
Copy link
Member

ํ‚น๊ฐ“๊ตํ™ฉ

Copy link
Member

@miniron-v miniron-v left a comment

Choose a reason for hiding this comment

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

์Šคํƒ์€ ์ž์ฃผ ์“ฐ์ด๋Š” ๋งŒํผ ๊ตฌํ˜„ํ•ด๋ณด๋Š” ๊ฒƒ๋„ ์ข‹์€ ๊ฒฝํ—˜์ด์ฃ ~ ๋ฐฑ์ค€์— ์ด๋Ÿฐ ๋ฌธ์ œ๊ฐ€ ์žˆ๋Š” ์ค„์€ ๋ชฐ๋ž๋„ค์š”. (๊ทธ๋ฆฌ๊ณ  ํŒŒ์ด์ฌ.. ๋Š˜ ๋Š๋ผ์ง€๋งŒ ์ฐธ ํŽธํ•˜๋„ค์š”...)

์ฝ”ํ…Œ์—” ๋ฌธ์ œ๊ฐ€ ์—†์ง€๋งŒ, ํ˜ธ์˜ฅ์‹œ๋‚˜ ์Šคํƒ์„ ์ง์ ‘ ๊ตฌํ˜„ํ•ด์•ผ ํ•˜๋Š” ์ƒํ™ฉ์ด ์˜จ๋‹ค๋ฉด ์˜ˆ์™ธ ์ฒ˜๋ฆฌ๋ฅผ ๊ผญ ํ•ด์ค˜์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด ์ž…๋ ฅ์œผ๋กœ push 1 word๊ฐ™์€ ๊ฒŒ ์˜จ๋‹ค๊ฑฐ๋‚˜... ์ด๋Ÿด ๋•Œ ์–ด๋–ป๊ฒŒ ์ฒ˜๋ฆฌํ•  ๊ฑด์ง€(์ž˜๋ชป๋œ ์ž…๋ ฅ ์—๋Ÿฌ๋ฅผ ๋„์šธ์ง€, ์ฒซ ๊ธ€์ž๋งŒ ๋„ฃ์–ด์ค„ ์ง€, ๋‹ค ๋„ฃ์–ด์ค„ ์ง€ ๋“ฑ) ์ •ํ•ด๋‘์‹œ๋ฉด ํ”„๋กœ๊ทธ๋žจ ๊ฐœ๋ฐœ ์ค‘์— ์˜ˆ๊ธฐ์น˜ ๋ชปํ•œ ์˜ค๋ฅ˜๋ฅผ ๋งŒ๋‚˜์ง„ ์•Š์„ ๊ฑฐ์˜ˆ์š”.

๊ทธ๋ž˜๋„ ํ›Œ๋ฅญํ•˜๊ฒŒ ๊ตฌํ˜„ํ•ด์ฃผ์…จ๋„ค์š”. ๊ณ ์ƒํ•˜์…จ์Šต๋‹ˆ๋‹ค!

@Redish03
Copy link
Collaborator

์Šคํƒ์€ ์ž์ฃผ ์“ฐ์ด๋Š” ๋งŒํผ ๊ตฌํ˜„ํ•ด๋ณด๋Š” ๊ฒƒ๋„ ์ข‹์€ ๊ฒฝํ—˜์ด์ฃ ~ ๋ฐฑ์ค€์— ์ด๋Ÿฐ ๋ฌธ์ œ๊ฐ€ ์žˆ๋Š” ์ค„์€ ๋ชฐ๋ž๋„ค์š”. (๊ทธ๋ฆฌ๊ณ  ํŒŒ์ด์ฌ.. ๋Š˜ ๋Š๋ผ์ง€๋งŒ ์ฐธ ํŽธํ•˜๋„ค์š”...)

์ฝ”ํ…Œ์—” ๋ฌธ์ œ๊ฐ€ ์—†์ง€๋งŒ, ํ˜ธ์˜ฅ์‹œ๋‚˜ ์Šคํƒ์„ ์ง์ ‘ ๊ตฌํ˜„ํ•ด์•ผ ํ•˜๋Š” ์ƒํ™ฉ์ด ์˜จ๋‹ค๋ฉด ์˜ˆ์™ธ ์ฒ˜๋ฆฌ๋ฅผ ๊ผญ ํ•ด์ค˜์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด ์ž…๋ ฅ์œผ๋กœ push 1 word๊ฐ™์€ ๊ฒŒ ์˜จ๋‹ค๊ฑฐ๋‚˜... ์ด๋Ÿด ๋•Œ ์–ด๋–ป๊ฒŒ ์ฒ˜๋ฆฌํ•  ๊ฑด์ง€(์ž˜๋ชป๋œ ์ž…๋ ฅ ์—๋Ÿฌ๋ฅผ ๋„์šธ์ง€, ์ฒซ ๊ธ€์ž๋งŒ ๋„ฃ์–ด์ค„ ์ง€, ๋‹ค ๋„ฃ์–ด์ค„ ์ง€ ๋“ฑ) ์ •ํ•ด๋‘์‹œ๋ฉด ํ”„๋กœ๊ทธ๋žจ ๊ฐœ๋ฐœ ์ค‘์— ์˜ˆ๊ธฐ์น˜ ๋ชปํ•œ ์˜ค๋ฅ˜๋ฅผ ๋งŒ๋‚˜์ง„ ์•Š์„ ๊ฑฐ์˜ˆ์š”.

๊ทธ๋ž˜๋„ ํ›Œ๋ฅญํ•˜๊ฒŒ ๊ตฌํ˜„ํ•ด์ฃผ์…จ๋„ค์š”. ๊ณ ์ƒํ•˜์…จ์Šต๋‹ˆ๋‹ค!

์˜ˆ์™ธ ์ฒ˜๋ฆฌ์— ๋Œ€ํ•œ ์ฝ”๋ฉ˜ํŠธ ๋ง๋ถ™์ด์ž๋ฉด...์˜ˆ๋ฅผ ๋“ค๋ฉด stack์˜ ํฌ๊ธฐ๋ฅผ ์ง€์ •ํ•ด์คฌ๋Š”๋ฐ ๊ทธ ํฌ๊ธฐ๋ฅผ ๋„˜์–ด์„œ๊ฒŒ ๋ฐ์ดํ„ฐ๋ฅผ ์ง‘์–ด๋„ฃ์—ˆ๊ฑฐ๋‚˜, ์•„๋‹ˆ๋ฉด ์ž…๋ ฅ์œผ๋กœ push๋งŒ ์ฃผ์–ด์ง€๊ณ  ๊ทธ ๋’ค์— ๋„ฃ์„ ๊ฐ’์„ ์•ˆ ๋„ฃ๋Š”, null์„ ๋„ฃ๋Š” ๊ฒฝ์šฐ์— ๋Œ€ํ•œ ์ฒ˜๋ฆฌ๋„ ํ•ด์ค˜์•ผ ํ•˜๊ณ , ๋ฏผ์ฒ ๋‹˜ ์ฒ˜๋Ÿผ push ๋‹ค์Œ์— ์ •์ˆ˜ํ˜• ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ string, char ๋“ฑ์˜ ๋ฐ์ดํ„ฐ๊ฐ€ ๋“ค์–ด์˜ค๋Š” ๊ฒฝ์šฐ์— ๋Œ€ํ•ด์„œ ์ฒ˜๋ฆฌ๋ฅผ ํ•ด์ค€๋‹ค๊ฑฐ๋‚˜...๋“ฑ๋“ฑ๋“ฑ๋“ฑ ์˜ˆ์™ธ ์ฒ˜๋ฆฌ๋ฅผ ํ•˜๋ฉด ํ• ์ˆ˜๋ก ์ฝ”๋“œ๋Š” ๊ธธ์–ด์งˆ ์ˆ˜๋„ ์žˆ์–ด๋„ ์‚ฌ์šฉ์ž ๊ด€์ (์•Œ๊ณ ๋ฆฌ์ฆ˜ ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ ๊ฐœ๋ฐœ์—์„œ๋„)์—์„œ ๋˜๊ฒŒ ์ค‘์š”ํ•œ ๊ฐœ๋…์ด๋ผ ์•Œ๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™๋„ค์š”..!

Copy link
Collaborator

@Redish03 Redish03 left a comment

Choose a reason for hiding this comment

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

๊ณ ์ƒํ•˜์…จ์Šต๋‹ˆ๋‹ค :) ์ฝ”๋“œ ์ƒ์œผ๋กœ๋Š” ๋”ฑํžˆ ๋งํ•  ๊ฑด ์—†๋Š” ๊ฒƒ ๊ฐ™๋„ค์š”!

ํŒŒ์ผ ๋ช… ํ•œ๊ธ€๋กœ ๋งŒ๋“œ๋Š” ๊ฑด ๋น„์ถ”ํ•ฉ๋‹ˆ๋‹ค..ใ…Žใ…Ž

Copy link
Member

@bomik0221 bomik0221 left a comment

Choose a reason for hiding this comment

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

์ €๋„ ์ฝ”๋“œ ๊ด€๋ จ์œผ๋กœ ๋“œ๋ฆด ๋ง์”€์€ ์—†๋„ค์š”! ์ €๋„ ์ด ๋ฌธ์ œ C++ ๋กœ ํ•ด๋ณด๋ ค๋‹ค๊ฐ€ ์ฝ”๋“œ ๋„ˆ๋ฌด ๊ธธ์–ด์ ธ์„œ ๊ท€์ฐฎ์•„์„œ ๊ทธ๋งŒ๋‘” ์ ์ด ์žˆ๋Š”๋ฐ, ๋‹ค๋ฅธ ๋ถ„๋“ค ์ฝ”๋ฉ˜ํŠธ ๋ณด๋‹ˆ ์˜ˆ์™ธ ์ฒ˜๋ฆฌ ๋“ฑ๋“ฑ.. ๋ฐฐ์šธ ์ ์ด ๋งŽ์€ ๋ฌธ์ œ ๊ฐ™๋„ค์š”. ๋‹ค์‹œ ํ’€์–ด๋ด์•ผ๊ฒ ์–ด์š”.... ใ…Žใ…Ž

@2secondag
Copy link
Collaborator Author

์Šคํƒ์€ ์ž์ฃผ ์“ฐ์ด๋Š” ๋งŒํผ ๊ตฌํ˜„ํ•ด๋ณด๋Š” ๊ฒƒ๋„ ์ข‹์€ ๊ฒฝํ—˜์ด์ฃ ~ ๋ฐฑ์ค€์— ์ด๋Ÿฐ ๋ฌธ์ œ๊ฐ€ ์žˆ๋Š” ์ค„์€ ๋ชฐ๋ž๋„ค์š”. (๊ทธ๋ฆฌ๊ณ  ํŒŒ์ด์ฌ.. ๋Š˜ ๋Š๋ผ์ง€๋งŒ ์ฐธ ํŽธํ•˜๋„ค์š”...)
์ฝ”ํ…Œ์—” ๋ฌธ์ œ๊ฐ€ ์—†์ง€๋งŒ, ํ˜ธ์˜ฅ์‹œ๋‚˜ ์Šคํƒ์„ ์ง์ ‘ ๊ตฌํ˜„ํ•ด์•ผ ํ•˜๋Š” ์ƒํ™ฉ์ด ์˜จ๋‹ค๋ฉด ์˜ˆ์™ธ ์ฒ˜๋ฆฌ๋ฅผ ๊ผญ ํ•ด์ค˜์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด ์ž…๋ ฅ์œผ๋กœ push 1 word๊ฐ™์€ ๊ฒŒ ์˜จ๋‹ค๊ฑฐ๋‚˜... ์ด๋Ÿด ๋•Œ ์–ด๋–ป๊ฒŒ ์ฒ˜๋ฆฌํ•  ๊ฑด์ง€(์ž˜๋ชป๋œ ์ž…๋ ฅ ์—๋Ÿฌ๋ฅผ ๋„์šธ์ง€, ์ฒซ ๊ธ€์ž๋งŒ ๋„ฃ์–ด์ค„ ์ง€, ๋‹ค ๋„ฃ์–ด์ค„ ์ง€ ๋“ฑ) ์ •ํ•ด๋‘์‹œ๋ฉด ํ”„๋กœ๊ทธ๋žจ ๊ฐœ๋ฐœ ์ค‘์— ์˜ˆ๊ธฐ์น˜ ๋ชปํ•œ ์˜ค๋ฅ˜๋ฅผ ๋งŒ๋‚˜์ง„ ์•Š์„ ๊ฑฐ์˜ˆ์š”.
๊ทธ๋ž˜๋„ ํ›Œ๋ฅญํ•˜๊ฒŒ ๊ตฌํ˜„ํ•ด์ฃผ์…จ๋„ค์š”. ๊ณ ์ƒํ•˜์…จ์Šต๋‹ˆ๋‹ค!

์˜ˆ์™ธ ์ฒ˜๋ฆฌ์— ๋Œ€ํ•œ ์ฝ”๋ฉ˜ํŠธ ๋ง๋ถ™์ด์ž๋ฉด...์˜ˆ๋ฅผ ๋“ค๋ฉด stack์˜ ํฌ๊ธฐ๋ฅผ ์ง€์ •ํ•ด์คฌ๋Š”๋ฐ ๊ทธ ํฌ๊ธฐ๋ฅผ ๋„˜์–ด์„œ๊ฒŒ ๋ฐ์ดํ„ฐ๋ฅผ ์ง‘์–ด๋„ฃ์—ˆ๊ฑฐ๋‚˜, ์•„๋‹ˆ๋ฉด ์ž…๋ ฅ์œผ๋กœ push๋งŒ ์ฃผ์–ด์ง€๊ณ  ๊ทธ ๋’ค์— ๋„ฃ์„ ๊ฐ’์„ ์•ˆ ๋„ฃ๋Š”, null์„ ๋„ฃ๋Š” ๊ฒฝ์šฐ์— ๋Œ€ํ•œ ์ฒ˜๋ฆฌ๋„ ํ•ด์ค˜์•ผ ํ•˜๊ณ , ๋ฏผ์ฒ ๋‹˜ ์ฒ˜๋Ÿผ push ๋‹ค์Œ์— ์ •์ˆ˜ํ˜• ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ string, char ๋“ฑ์˜ ๋ฐ์ดํ„ฐ๊ฐ€ ๋“ค์–ด์˜ค๋Š” ๊ฒฝ์šฐ์— ๋Œ€ํ•ด์„œ ์ฒ˜๋ฆฌ๋ฅผ ํ•ด์ค€๋‹ค๊ฑฐ๋‚˜...๋“ฑ๋“ฑ๋“ฑ๋“ฑ ์˜ˆ์™ธ ์ฒ˜๋ฆฌ๋ฅผ ํ•˜๋ฉด ํ• ์ˆ˜๋ก ์ฝ”๋“œ๋Š” ๊ธธ์–ด์งˆ ์ˆ˜๋„ ์žˆ์–ด๋„ ์‚ฌ์šฉ์ž ๊ด€์ (์•Œ๊ณ ๋ฆฌ์ฆ˜ ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ ๊ฐœ๋ฐœ์—์„œ๋„)์—์„œ ๋˜๊ฒŒ ์ค‘์š”ํ•œ ๊ฐœ๋…์ด๋ผ ์•Œ๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™๋„ค์š”..!

์˜ˆ์™ธ ์ฒ˜๋ฆฌ์— ๋Œ€ํ•ด์„œ๋„ ๋‹ค์‹œ ์ƒ๊ฐํ•ด๋ด์•ผ๊ฒ ๋„ค์š”~!

@2secondag 2secondag merged commit 04a2e25 into main Feb 19, 2024
@2secondag 2secondag deleted the 14-2secondag branch February 19, 2024 03:19
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.

5 participants