Read-and-analysis.md


๐Ÿ“„ ์ฝ๊ธฐ์™€ ๋ถ„์„

  • ์•Œ๊ณ ๋ฆฌ์ฆ˜ ๋ฌธ์ œ ํ•ด๊ฒฐ์˜ ๊ฐ€์žฅ ์ค‘์š”ํ•œ ๊ฒƒ

  • ๋ฌธ์ œ์˜ ์กฐ๊ฑด๋“ค์„ ์ถ”์ƒํ™”ํ•˜๋Š” ์—ฐ์Šต

  • ์‹œ๊ฐ„๋ณต์žก๋„/๊ณต๊ฐ„๋ณต์žก๋„ ์–ด๋ฆผ์žก๊ธฐ

์‹œ๊ฐ„๋ณต์žก๋„


  • ์–ด๋–ค ์ด์œ ๋กœ ์ฝ”๋“œ์˜ ์‹คํ–‰ ์‹œ๊ฐ„์ด ์˜ค๋ž˜ ๊ฑธ๋ฆด๊นŒ? => ์—ฐ์‚ฐ๋Ÿ‰

  • ์—ฐ์‚ฐ๋Ÿ‰์€ ์–ด๋–ค ๊ฐ’๊ณผ ์ƒ๊ด€์ด ์žˆ์„๊นŒ? => ์ž…๋ ฅ

  • ๋ชจ๋“  ์—ฐ์‚ฐ์„ Counting ํ•  ์ˆ˜ ์žˆ์„๊นŒ? => X

  • ์ตœ์•…์˜ ๊ฒฝ์šฐ์™€ ์ตœ์„ ์˜ ๊ฒฝ์šฐ? => X

  • Counting์— ๋”ฐ๋ผ ์‹คํ–‰์‹œ๊ฐ„์€? => X => ๋‹ค์–‘ํ•œ ์ด์œ (ํ•˜๋“œ์›จ์–ด ์ฐจ์ด, ์—ฐ์‚ฐ ์ฒ˜๋ฆฌ์†๋„ ๋“ฑ๋“ฑ)๋กœ ์ •ํ™•ํ•œ ์‹คํ–‰์‹œ๊ฐ„์ด๋‚˜ ์‹œ๊ฐ„๋ณต์žก๋„๋ฅผ ๊ตฌํ•˜๊ธฐ๋Š” ํž˜๋“ค๋‹ค

๊ทธ๋ž˜์„œ!

๐Ÿ˜ ๋Œ€์ถฉ ๊ณ„์‚ฐํ•˜์ž => ์ ๊ทผ์  ํ‘œ๊ธฐ๋ฒ•

ํ‘œํ˜„๋ฒ• : Big-O Notation

  • ์ž…๋ ฅ์ด N์ผ๋•Œ, ์—ฐ์‚ฐ ํšŸ์ˆ˜๊ฐ€ ์ตœ์•…์ด 2N^2 + 4N์ด๋ผ๋ฉด?

  • O(N^2) N์ด ๋ฌดํ•œ๋Œ€๋กœ ์ปค์งˆ ๋•Œ, ๊ฐ€์žฅ ๋งŽ์€ ์˜ํ–ฅ์„ ์ฃผ๋Š” ํ•ญ์€ ์ตœ๊ณ ์ฐจํ•ญ์ด๋‹ค! big-onotation

๋ฌธ์ œ ํ‘ธ๋Š” ์ˆœ์„œ


๋ฌธ์ œํ’€์ด ํ•  ๋•Œ๋Š” ๐Ÿ‘ฟ์ตœ์•…์˜ ๊ฒฝ์šฐ๐Ÿ‘ฟ๋ฅผ ์ƒ๊ฐํ•˜์ž!

  1. ์‹œ๊ฐ„, ๋ฉ”๋ชจ๋ฆฌ, ์ž…๋ ฅ, ์ถœ๋ ฅ ๋ณด๊ณ  ํ’€์ด ๊ฐ ์žก๊ธฐ

  • ํ‘œํ˜„๋ฒ•๊ณผ ๊ฐ

  • ์‹œ๊ฐ„๊ณผ ๊ณต๊ฐ„ ์ฐจ์›์—์„œ ๊ฐ๊ฐ ๋‹ค๋ฅผ ์ˆ˜ ์žˆ์Œ => ์‹œ๊ฐ„ ๋ณต์žก๋„์™€ ๊ณต๊ฐ„๋ณต์žก๋„

  1. Naive(๋ฌด์ž‘์ •)ํ•œ ํ’€์ด ๋– ์˜ฌ๋ฆฌ๊ธฐ

  2. ์ค‘๊ฐ„ ๊ณผ์ •์— ๋ฐ˜๋“œ์‹œ ํ•„์š”ํ•œ ๋กœ์ง ์ƒ๊ฐํ•˜๊ธฐ

  3. ์˜ˆ์ œ ์ž…๋ ฅ๊ณผ ์˜ˆ์ œ ์ถœ๋ ฅ ๋งค์นญ

  4. ์ฝ”๋“œ ์ž‘์„ฑ

์ž…๋ ฅ๊ณผ ์ดˆ๊ธฐํ™” ํŒ - Map๊ณผ Comprehension


์ž…๋ ฅ์˜ ๋Œ€ํ‘œ์ ์ธ ์‚ฌ๋ก€ 3๊ฐ€์ง€

  • ์ˆ˜

  • ๋ฌธ์ž์—ด(๋ฌธ์ž ๋ฐฐ์—ด)

  • ๋ฐฐ์—ด

Map(x, y)

  • xํ•จ์ˆ˜๋ฅผ y์˜ ์›์†Œ์— ๋ชจ๋‘ ์ ์šฉํ•œ map ๊ฐ์ฒด๋ฅผ ๋ฐ˜ํ™˜

# ๋ฌธ์ž๋กœ ์ž…๋ ฅ๋œ 4๊ฐœ์˜ ์ˆซ์ž๋ฅผ intํ˜•์œผ๋กœ ๋งŒ๋“ค์–ด ์ถœ๋ ฅ
num = [input() for i in range(4)]
print(map(int, num))
  • List Comprehension

    • List ์ดˆ๊ธฐํ™”๋Š” comprehension์œผ๋กœ!

n_list = [0 for _ in range(n)]

์—๋Ÿฌ ๋ฉ”์‹œ์ง€ - Accepted์™€ Wrong Answer


์ถ”์ƒํ™”๊ฐ€ ๊ธฐ๋Šฅ๋ถ„๋ฆฌ - ํ•จ์ˆ˜์˜ ํ™œ์šฉ

  • TestCase๊ฐ€ ๋งŽ์€ ๋ฌธ์ œ

  • ๊ธฐ๋Šฅ์ด ๋ถ„๋ฆฌ๋˜๋Š” ๋ฌธ์ œ

=> ์ ์ ˆํ•˜๊ฒŒ ํ•จ์ˆ˜๋กœ ๋ถ„ํ• ํ•˜์—ฌ ๊ฐ€๋…์„ฑ์„ ๋†’์ด๊ณ  mainํ•จ์ˆ˜๋ฅผ ๊ฐ€๋ณ๊ฒŒ ํ•˜์ž!

=> psedo-code ์ž‘์„ฑํ•˜๋“ฏ์ด ๊ฐ„๋žตํ•˜๊ฒŒ

๊ฐ€๋…์„ฑ - ์กฐ๊ฑด๋ฌธ, ๋ฐ˜๋ณต๋ฌธ, ํ•จ์ˆ˜ ๋ชจ๋‘ ์ค„์ผ ๋ถ€๋ถ„ ์กด์žฌ


for i in range(N):
  for j in range(N):
    for k in range(N):
#์œ„์™€ ๋™์ผํ•œ ์ฝ”๋“œ
for num in range(N**3):
  i, j, k = num // (N*N), num // N % N, num %N

=> ๋‹ค์ค‘๋ฐ˜๋ณต๋ฌธ ์‚ฌ์šฉ์‹œ ์ˆ˜ํ•™์ ์ธ ๋ฐฉ๋ฒ•(๋ชซ๊ณผ ๋‚˜๋จธ์ง€, ์ง„๋ฒ• ๋“ฑ)์„ ์ด์šฉํ•˜์—ฌ ๊ฐ€๋ณ๊ฒŒ ๋ณ€๊ฒฝ!

for i in range(N):
  if state:
    process()
#์œ„์™€ ๋‹ค๋ฅด๊ฒŒ
for i in range(N):
  if not state: continue
  process()

=> ์กฐ๊ฑด์— ๋งž์ง€ ์•Š๋Š” ๊ฒฝ์šฐ๋ฅผ continue๋ฅผ ํ†ตํ•ด ๋ฐฐ์ œ, ๋ฐ˜๋ณต๋ฌธ ๋‚ด๋ถ€์˜ indent๋ฅผ ์ค„์ผ ์ˆ˜ ์žˆ์Œ

#์ผ๋ฐ˜์ ์ธ if else ์กฐ๊ฑด๋ฌธ ์‚ฌ์šฉ
if x:
  return True
else:
  return False

#์•„๋ž˜์™€ ๊ฐ™์€ ๋ฐฉ๋ฒ•์œผ๋กœ 
if x: return True
return False

# if else 3ํ•ญ ์—ฐ์‚ฐ์ž์˜ ํ™œ์šฉ
return True if x else False

๋ช…๋ช…๋ฒ• - Snake, Camel, Pascal


Camel ํ‘œ๊ธฐ๋ฒ•

  • ๊ฐ ๋‹จ์–ด์˜ ์ฒซ ๊ธ€์ž๋ฅผ ๋Œ€๋ฌธ์ž๋กœ ์ ๋Š” ๋ฐฉ๋ฒ•

  • ๋‹จ, ๊ฐ€์žฅ ์ฒซ ๊ธ€์ž๋Š” ์†Œ๋ฌธ์ž๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.

ex) camelCase, firstNum, thisIsCamelCase, howToSolveThisProblem

Snake ํ‘œ๊ธฐ๋ฒ•

  • ์†Œ๋ฌธ์ž๋งŒ ์‚ฌ์šฉํ•˜๊ณ  ๊ฐ ๋‹จ์–ด์˜ ์‚ฌ์ด์— ์–ธ๋”๋ฐ”(_)๋ฅผ ๋„ฃ์–ด์„œ ์ ๋Š” ๋ฐฉ๋ฒ•

ex) snake_case, variable_n, this_is_snake_case, how_to_solve_this_problem

Pascal ํ‘œ๊ธฐ๋ฒ•

  • Camel ํ‘œ๊ธฐ๋ฒ•๊ณผ ๊ฐ™์ง€๋งŒ, ๊ฐ€์žฅ ์ฒซ ๊ธ€์ž๋„ ๋Œ€๋ฌธ์ž๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.

ex) PascalCase, VariableN, ThisIsPascalCase, HowToSolveThisProblem

PEP8 ๋ช…๋ช…๊ทœ์น™

  • ํ•จ์ˆ˜, ๋ณ€์ˆ˜, Attribute๋Š” Snakeํ‘œ๊ธฐ๋ฒ• ์‚ฌ์šฉ

  • ํด๋ž˜์Šค๋Š” Pascal ํ‘œ๊ธฐ๋ฒ• ์‚ฌ์šฉ

  • ๋ชจ๋“ˆ ์ƒ์ˆ˜๋Š” ๋ชจ๋‘ ๋Œ€๋ฌธ์ž๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ๋‹จ์–ด๋งˆ๋‹ค ๋ฐ‘์ค„๋กœ ์—ฐ๊ฒฐํ•˜๋Š” ALL_CAP ํฌ๋งท ์‚ฌ์šฉ ex) MAX_COUNT = 100

  • ํด๋ž˜์Šค์˜ protected instanced attribute๋Š” ํ•˜๋‚˜์˜ ๋ฐ‘์ค„๋กœ ์‹œ์ž‘

  • ํด๋ž˜์Šค์˜ privated instanced attirbute๋Š” ๋‘๊ฐœ์˜ ๋ฐ‘์ค„๋กœ ์‹œ์ž‘

Last updated