์ ์ฒด ๊ธ
-
[Python] 2016๋ Algorithm/ํ๋ก๊ทธ๋๋จธ์ค 2021. 5. 1. 23:33
1. ๋ฌธ์ ๐ 2. ์ ์ถ๋ ฅ ์ ๐ 3. ์๊ณ ๋ฆฌ์ฆ โ ๊ฐ ๋ฌ์ ๋ง์ผ์ ๋ด์ ๋ฆฌ์คํธ๋ฅผ ๋ง๋ ๋ค 1์ 1์ผ์ด FRI์ด๋ฏ๋ก, FRI๋ถํฐ ์์ํ๋ ์์ผ ๋ฆฌ์คํธ๋ฅผ ๋ง๋ ๋ค. a-1๋ฌ๊น์ง์ ๋ง์ผ์ ๋ํ ํ, b-1์ ๋ํ๊ณ %7๋ฒ์งธ์ ์์ผ์ ๋ฆฌํดํ๋ค. -> 1์1์ผ์ด FRI์ด๋ฏ๋ก 1์ 1์ผ์ด 0๋ฒ์งธ๋ฅผ ๋ง๋ค๊ธฐ ์ํด ๊ฐ๊ฐ -1์ ํ๋ค. 4. ์์ค์ฝ๋ ๐ป def solution(a,b): months = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] days = ['FRI', 'SAT', 'SUN', 'MON', 'TUE', 'WED', 'THU'] return days[(sum(months[:a-1])+b-1)%7]
-
[Python] ์ฒด์ก๋ณตAlgorithm/ํ๋ก๊ทธ๋๋จธ์ค 2021. 5. 1. 00:17
1. ๋ฌธ์ ๐ 2. ์ ์ถ๋ ฅ ์ ๐ 3. ์๊ณ ๋ฆฌ์ฆ โ ์ ํ์ฌํญ์ ์ฌ๋ฒ ์ฒด์ก๋ณต์ ๊ฐ์ ธ์จ ์ฌ๋๋ ๋๋ ๋นํ ์ ์๋ค ๋ผ๊ณ ์ ํ์๋ค ์ด์ ์ ๊ณ ๋ คํ์ฌ, ์ค๋ณต๋๋ ๊ฒ๋ค์ ๋นผ์ค๋ค. ์ฐ์ ์์๋ฅผ ์ผ์ชฝ์ผ๋ก ๋์ง, ์ค๋ฅธ์ชฝ์ผ๋ก ๋์ง ์ ํํ๋ค n = 5, lost = [2, 4], reserve[3, 5] ๊ฐ์ ์ค๋ฅธ์ชฝ์ผ๋ก ์ฐ์ ์์๋ฅผ ๋๊ฒ ๋๋ฉด, ์ต๋๊ฐ์ด ๋์ฌ ์ ์๋ค. ๋ฐ๋ผ์ ์ผ์ชฝ๋ถํฐ ์ฐ์ ์์๋ฅผ ๋ฌ์ผํ๋ค. ์ฌ๋ถํ์ -1 ๊ฐ๊ณผ ๋๋ ํ์ ์ด ๊ฐ์ผ๋ฉด ๋๋ํ์์ ์์ค๋ค. ์ด ํ์์ ์์์ ๋๋ ํ์์ ์๋ฅผ ๋นผ์ค๋ค. 4. ์์ค์ฝ๋ ๐ป def solution(n, lost, reserve): set_reserve = set(reserve) - set(lost) set_lost = set(lost) - set(reserve) for i ..
-
[Python] ๋ชจ์๊ณ ์ฌAlgorithm/ํ๋ก๊ทธ๋๋จธ์ค 2021. 4. 29. 17:23
1. ๋ฌธ์ ๐ 2. ์ ์ถ๋ ฅ ์ ๐ 3. ์๊ณ ๋ฆฌ์ฆ โ ๊ฐ์ ํ์์ด ๋ง์ถ ์ ๋ต์ ๊ฐ์๋ฅผ list๋ฅผ ๋ง๋ ๋ค ํ์๋ง๋ค ๋ฐ๋ณต๋๋ ๋ต์ ๊ธธ์ด๊ฐ ๋ค๋ฅด๋ฏ๋ก, ์ ๋ต์ ๊ธธ์ด๋ฅผ ๋๋ ๋๋จธ์ง๋ก ๋น๊ต ์ ๋ต์ด๋ฉด ๊ฐ์ ๊ฐ์์ +1์ ํด์ค๋ค ๊ฐ์ฅ ๋ง์ด ๋ง์ถ ํ์์ ๋ฆฌํดํ๋ฉด ๋๋ฏ๋ก, ๊ฐ์ฅ ๋ง์ด ๋ง์ถ ๊ฐ์์ ๋น๊ตํ์ฌ ๊ฐ์ผ๋ฉด answer์ ๋ฃ์ด์ค๋ค. 4. ์์ค์ฝ๋ ๐ป def solution(answers): st1 = [1, 2, 3, 4, 5] st2 = [2, 1, 2, 3, 2, 4, 2, 5] st3 = [3, 3, 1, 1, 2, 2, 4, 4, 5, 5] answer = [] cnt = [0, 0, 0] for i in range(len(answers)): if answers[i] == st1[i%len(st1)]: cnt[0..
-
[Python] ์์ฃผํ์ง ๋ชปํ ์ ์Algorithm/ํ๋ก๊ทธ๋๋จธ์ค 2021. 4. 27. 22:31
http:// programmers.co.kr/learn/courses/30/lessons/42576?language=python3 1. ๋ฌธ์ ๐ ์๋ง์ ๋ง๋ผํค ์ ์๋ค์ด ๋ง๋ผํค์ ์ฐธ์ฌํ์์ต๋๋ค. ๋จ ํ ๋ช ์ ์ ์๋ฅผ ์ ์ธํ๊ณ ๋ ๋ชจ๋ ์ ์๊ฐ ๋ง๋ผํค์ ์์ฃผํ์์ต๋๋ค. ๋ง๋ผํค์ ์ฐธ์ฌํ ์ ์๋ค์ ์ด๋ฆ์ด ๋ด๊ธด ๋ฐฐ์ด participant์ ์์ฃผํ ์ ์๋ค์ ์ด๋ฆ์ด ๋ด๊ธด ๋ฐฐ์ด completion์ด ์ฃผ์ด์ง ๋, ์์ฃผํ์ง ๋ชปํ ์ ์์ ์ด๋ฆ์ return ํ๋๋ก solution ํจ์๋ฅผ ์์ฑํด์ฃผ์ธ์. 2. ์ ์ถ๋ ฅ ์ ๐ 3. ์๊ณ ๋ฆฌ์ฆ โ ์์ฃผํ์ง ๋ชปํ ์ ์๋ ๋ฌด์กฐ๊ฑด 1๋ช ์ด๊ธฐ ๋๋ฌธ์ Counter ํจ์๋ฅผ ์ด์ฉํ๋ค Counterํจ์๋ฅผ ์ด์ฉํ์ฌ ๋ ๊ฐ์ฒด๋ฅผ ๋นผ์ฃผ๊ฒ ๋๋ฉด, ๊ฒฐ๊ตญ ์์ฃผํ์ง ๋ชปํ ์ ์ ํ๋ช ๋ง ๋จ๊ฒ๋๋ค Counter๋ key..
-
[Python] ํฌ๋ ์ธ ์ธํ๋ฝ๊ธฐAlgorithm/ํ๋ก๊ทธ๋๋จธ์ค 2021. 4. 26. 23:59
1. ๋ฌธ์ ๐ ๊ฒ์ ํ๋ฉด์ ๊ฒฉ์์ ์ํ๊ฐ ๋ด๊ธด 2์ฐจ์ ๋ฐฐ์ด board์ ์ธํ์ ์ง๊ธฐ ์ํด ํฌ๋ ์ธ์ ์๋์ํจ ์์น๊ฐ ๋ด๊ธด ๋ฐฐ์ด moves๊ฐ ๋งค๊ฐ๋ณ์๋ก ์ฃผ์ด์ง ๋, ํฌ๋ ์ธ์ ๋ชจ๋ ์๋์ํจ ํ ํฐํธ๋ ค์ ธ ์ฌ๋ผ์ง ์ธํ์ ๊ฐ์๋ฅผ return ํ๋๋ก solution ํจ์๋ฅผ ์์ฑํด์ฃผ์ธ์. 2. ์ ์ถ๋ ฅ ์ ๐ 3. ์๊ณ ๋ฆฌ์ฆ โ ํ๋ ์ฉ ๋น๊ตํ๊ธฐ ์ํด moves์ board๋ฅผ ๊ฐ๊ฐ for๋ฌธ์ผ๋ก ๊บผ๋ด์ค๋ค 0์ด ์๋ ์ (์ธํ์ด ์๋ ๊ฒ) basket ๋ฐฐ์ด์ ๋ฃ์ด์ค๋ค ๋ฐฐ์ด์ด ๋ง์ง๋ง ์ซ์์ ๊ฐ์ ๊ฒฝ์ฐ answer ์ 2๋ฅผ ๋ํด์ค๋ค → ์ด 2๊ฐ๊ฐ ์ฌ๋ผ์ง๋ ๊ฒ์ด๊ธฐ ๋๋ฌธ์ ์ฌ๋ผ์ง 2๊ฐ๋ฅผ basket์์ ์์ ์ค๋ค 4. ์์ค์ฝ๋ ๐ป def solution(board, moves): answer = 0 bucket = [] for mov..
-
04. ์คํ์ ์์ฉ - ๊ดํธ ๊ฒ์ฌ ๋ฌธ์ ์๊ณ ๋ฆฌ์ฆComputer Science/Data Structure 2021. 4. 10. 11:29
4.4 ์คํ์ ์์ฉ ๊ดํธ ๊ฒ์ฌ ๋ฌธ์ ํ๋ก๊ทธ๋จ์์ ์ฌ์ฉ๋๋ ๊ดํธ์๋ [, ], {, }, (, ) ๋ฑ์ด ์๋ค. ์คํ์ ์ด์ฉํ์ฌ ์ฌ๋ฐ๋ฅด๊ฒ ์ฌ์ฉ๋์๋์ง ์คํ์ ํ์ฉํ์ฌ ๊ตฌํํด๋ณด์ ์กฐ๊ฑด ์ผ์ชฝ ๊ดํธ์ ๊ฐ์์ ์ค๋ฅธ์ชฝ ๊ดํธ์ ๊ฐ์๊ฐ ๋์ผํด์ผํ๋ค. ๊ฐ์ ์ข ๋ฅ์ ๊ดํธ์์ ์ผ์ชฝ ๊ดํธ๋ ํญ์ ๋จผ์ ๋์์ผํ๋ค. ์๋ก ๋ค๋ฅธ ์ข ๋ฅ์ ์ผ์ชฝ ๊ดํธ์ ์ค๋ฅธ์ชฝ ๊ดํธ ์์ ๊ต์ฐจํ๋ฉด ์๋๋ค. ์๊ณ ๋ฆฌ์ฆ ๋ฌธ์์ด์ ์ฐจ๋ก๋๋ก ์กฐ์ฌํ๋ค ์ผ์ชฝ ๊ดํธ๋ฅผ ๋ง๋๋ฉด ์คํ์ ๋ฃ๊ณ , ์ค๋ฅธ์ชฝ ๊ดํธ๋ฅผ ๋ง๋๋ฉด ์คํ์์ ๊ฐ์ฅ ์ต๊ทผ์ ์ผ์ชฝ ๊ดํธ๋ฅผ ๊บผ๋ด์ด ๋ง๋ ์ง ํ์ธํ๋ค. ์ด ๋, ์คํ์ด ๋น์ด์์ผ๋ฉด ์กฐ๊ฑด1, ์กฐ๊ฑด2 ์๋ฐฐ ๊ดํธ์ ์ง์ด๋ง์ง์์ผ๋ฉด ์กฐ๊ฑด3 ์๋ฐฐ ๋ง์ง๋ง ๊ดํธ๊น์ง ์กฐ์ฌ๋ฅผ ๋ง์น ํ ์คํ์ ๊ดํธ๊ฐ ๋จ์์๋ค๋ฉด ์กฐ๊ฑด 1์ ์๋ฐฐ ๊ตฌํ #include #include #defi..
-
04. ์คํComputer Science/Data Structure 2021. 4. 10. 04:01
4.1 ์คํ์ด๋? ์คํ ๋ฐ์ดํฐ๋ฅผ ์ฐจ๊ณก ์ฐจ๊ณก ์์์ฌ๋ฆฐ ํํ๋ก ๋ฐ์ดํฐ๋ฅผ ์ถ์ํํ์ฌ ์๋ฃ๊ตฌ์กฐ๋ก ์ ์ํ ๊ฒ ์ฐํ์ ์์์ฌ๋ฆฐ ๋ชจ์ต, ๋ทํ ์ ์๊ฐ ์ฐจ๊ณก์ฐจ๊ณก ์์์ฌ๋ฆฐ ๋ชจ์ต ๊ณผ ๋น์ทํ๋ค. ํน์ง ๊ฐ์ ๊ตฌ์กฐ์ ๊ฐ์ ํฌ๊ธฐ์ ๋ฐ์ดํฐ๋ฅผ ์ ํด์ง ๋ฐฉํฅ์ผ๋ก๋ง ์์ ์ ์๋ค. top์ผ๋ก ์ ํ ํ ๊ณณ๋ง ์ ๊ทผ ๊ฐ๋ฅํ๋ค ํ์ ์ ์ถ(LIFO) ์ ๋์๊ตฌ์กฐ๋ฅผ ๊ฐ๋๋ค : ๊ฐ์ฅ ๋ง์ง๋ง์ ์ฝ์ ๋ ๋ฐ์ดํฐ๊ฐ ๊ฐ์ฅ ๋จผ์ ์ญ์ ๋๋ค ์์ - ์์คํ ์คํ์ ์ด์ฉํ ํจ์ํธ์ถ : ํจ์๋ ์คํ์ด ๋๋๋ฉด ์์ ์ ํธ์ถํ ํจ์๋ก ๋๋์ ๊ฐ์ผํ๋๋ฐ, ์ด๋ ์คํ์ ์ฌ์ฉํ๋ค. → ๋ณต๊ทํ ์ฃผ์๋ฅผ ๊ธฐ์ตํ๋ ๋ฐ ์ฌ์ฉ ๐คทโ๏ธ ์ ์ผ๊น์? ํจ์๋ ํธ์ถ๋ ์ญ์์ผ๋ก ๋์๊ฐ์ผ ํ๊ธฐ ๋๋ฌธ! void func2() { return; } void func1() { func2(); } int ..
-
03. ๋ฐฐ์ด, ๊ตฌ์กฐ์ฒด, ํฌ์ธํฐComputer Science/Data Structure 2021. 4. 5. 02:21
3.1 ๋ฐฐ์ด ๊ฐ๋ ๋์ผํ ํ์ ์ ๋ฐ์ดํฐ๋ฅผ ํ ๋ฒ์ ์ฌ๋ฌ๊ฐ ๋ง๋ค ๋ ์ฌ์ฉํ๋ ์๋ฃํ ์ธ๋ฑ์ค(index) ๋ฒํธ๋ฅผ ์ฌ์ฉํ์ฌ ์ฌ๋ฌ๊ฐ ๋ง๋ค ๋ ์ฌ์ฉํ๋ ์๋ฃํ ํน์ง ์ฐ์์ ์ธ ๋ฉ๋ชจ๋ฆฌ ํ ๋น์ด ๊ฐ๋ฅํ๋ค. index ๋ฒํธ๋ฅผ ์ด์ฉํ์ฌ ์ฝ๊ฒ ์ ๊ทผ ํ ์ ์๋ค. 1์ฐจ์ ๋ฐฐ์ด ์ ์ธ ์๋ฃํ ๋ฐฐ์ด์ด๋ฆ[๋ฐฐ์ด ์์์ ๊ฐ์]; int list[3]; ์ด๊ธฐํ ๋ฐฉ๋ฒ int list[3] = { 1, 2, 3 }; 2์ฐจ์ ๋ฐฐ์ด ์ ์ธ ์๋ฃํ ๋ฐฐ์ด์ด๋ฆ[ํ ์์์ ๊ฐ์][์ด ์์์ ๊ฐ์]; int list[3][5]; ์ขํ๋ผ๊ณ ์๊ฐํ๋ฉด ์ดํดํ๊ธฐ ํธํ๋ค. ์๋ฅผ ๋ค๋ฉด list[0][0] > (0, 0) , list[2][3] > (2, 3) 3.2 ๊ตฌ์กฐ์ฒด(Struct) ๊ฐ๋ ํ์ ์ด ๋ค๋ฅธ ๋ฐ์ดํฐ๋ฅผ ๋ฌถ๋ ๋ฐฉ๋ฒ ๋ฐฐ์ด๊ณผ์ ์ฐจ์ด์ : ๋ฐฐ์ด์ ํ์ ์ด ๊ฐ์ ๋ฐ์ด..