2021/1146 [CK] ์ฐ์ต๋ฌธ์ > ๋ฌธ์์ด ๋ด p์ y์ ๊ฐ์ ๋ฌธ์ ์ค๋ช ๋๋ฌธ์์ ์๋ฌธ์๊ฐ ์์ฌ์๋ ๋ฌธ์์ด s๊ฐ ์ฃผ์ด์ง๋๋ค. s์ 'p'์ ๊ฐ์์ 'y'์ ๊ฐ์๋ฅผ ๋น๊ตํด ๊ฐ์ผ๋ฉด True, ๋ค๋ฅด๋ฉด False๋ฅผ return ํ๋ solution๋ฅผ ์์ฑํ์ธ์. 'p', 'y' ๋ชจ๋ ํ๋๋ ์๋ ๊ฒฝ์ฐ๋ ํญ์ True๋ฅผ ๋ฆฌํดํฉ๋๋ค. ๋จ, ๊ฐ์๋ฅผ ๋น๊ตํ ๋ ๋๋ฌธ์์ ์๋ฌธ์๋ ๊ตฌ๋ณํ์ง ์์ต๋๋ค. ์๋ฅผ ๋ค์ด s๊ฐ "pPoooyY"๋ฉด true๋ฅผ return ํ๊ณ "Pyy"๋ผ๋ฉด false๋ฅผ return ํฉ๋๋ค. ์ ํ์ฌํญ ๋ฌธ์์ด s์ ๊ธธ์ด : 50 ์ดํ์ ์์ฐ์ ๋ฌธ์์ด s๋ ์ํ๋ฒณ์ผ๋ก๋ง ์ด๋ฃจ์ด์ ธ ์์ต๋๋ค. ์ ์ถ๋ ฅ ์ s answer "pPoooyY" true "Pyy" false ์ ์ถ๋ ฅ ์ ์ค๋ช ์ ์ถ๋ ฅ ์ #1 'p'์ ๊ฐ์ 2๊ฐ, 'y'์ ๊ฐ์ 2๊ฐ๋ก ๊ฐ์ผ๋ฏ๋ก true๋ฅผ return.. CodeKata/Programmers 2021. 11. 30. 0 [CK] ์ฐ์ต๋ฌธ์ > ๋ฌธ์์ด ๋ด๋ฆผ์ฐจ์์ผ๋ก ๋ฐฐ์นํ๊ธฐ ๋ฌธ์ ์ค๋ช ๋ฌธ์์ด s์ ๋ํ๋๋ ๋ฌธ์๋ฅผ ํฐ ๊ฒ๋ถํฐ ์์ ์์ผ๋ก ์ ๋ ฌํด ์๋ก์ด ๋ฌธ์์ด์ ๋ฆฌํดํ๋ ํจ์, solution์ ์์ฑํด์ฃผ์ธ์. s๋ ์๋ฌธ ๋์๋ฌธ์๋ก๋ง ๊ตฌ์ฑ๋์ด ์์ผ๋ฉฐ, ๋๋ฌธ์๋ ์๋ฌธ์๋ณด๋ค ์์ ๊ฒ์ผ๋ก ๊ฐ์ฃผํฉ๋๋ค. ์ ํ ์ฌํญ str์ ๊ธธ์ด 1 ์ด์์ธ ๋ฌธ์์ด์ ๋๋ค. ์ ์ถ๋ ฅ ์ s return "Zbcdefg" "gfedcbZ" Solution #include #include #include using namespace std; string solution(string s) { std::sort(s.begin(), s.end()); std::reverse(s.begin(), s.end()); return s; } ๋จ์ ์ฝ๋ #include #include #include #include using na.. CodeKata/Programmers 2021. 11. 30. 0 [CK] ์ฐ์ต๋ฌธ์ > ๋ฌธ์์ด ๋ค๋ฃจ๊ธฐ ๊ธฐ๋ณธ ๋ฌธ์ ์ค๋ช ๋ฌธ์์ด s์ ๊ธธ์ด๊ฐ 4 ํน์ 6์ด๊ณ , ์ซ์๋ก๋ง ๊ตฌ์ฑ๋ผ์๋์ง ํ์ธํด์ฃผ๋ ํจ์, solution์ ์์ฑํ์ธ์. ์๋ฅผ ๋ค์ด s๊ฐ "a234"์ด๋ฉด False๋ฅผ ๋ฆฌํดํ๊ณ "1234"๋ผ๋ฉด True๋ฅผ ๋ฆฌํดํ๋ฉด ๋ฉ๋๋ค. ์ ํ ์ฌํญ s๋ ๊ธธ์ด 1 ์ด์, ๊ธธ์ด 8 ์ดํ์ธ ๋ฌธ์์ด์ ๋๋ค. ์ ์ถ๋ ฅ ์ s return "a234" false "1234" true Solution #include #include using namespace std; bool solution(string s) { if (s.length() != 4 && s.length() != 6) return false; for (auto x : s) if (x < '0' || '9' < x) return false; return true; } ๋จ์ ์ฝ.. CodeKata/Programmers 2021. 11. 30. 0 [CK] ์ฐ์ต๋ฌธ์ > ๋ฌธ์์ด ๋ด ๋ง์๋๋ก ์ ๋ ฌํ๊ธฐ ๋ฌธ์ ์ค๋ช ๋ฌธ์์ด๋ก ๊ตฌ์ฑ๋ ๋ฆฌ์คํธ strings์, ์ ์ n์ด ์ฃผ์ด์ก์ ๋, ๊ฐ ๋ฌธ์์ด์ ์ธ๋ฑ์ค n๋ฒ์งธ ๊ธ์๋ฅผ ๊ธฐ์ค์ผ๋ก ์ค๋ฆ์ฐจ์ ์ ๋ ฌํ๋ ค ํฉ๋๋ค. ์๋ฅผ ๋ค์ด strings๊ฐ ["sun", "bed", "car"]์ด๊ณ n์ด 1์ด๋ฉด ๊ฐ ๋จ์ด์ ์ธ๋ฑ์ค 1์ ๋ฌธ์ "u", "e", "a"๋ก strings๋ฅผ ์ ๋ ฌํฉ๋๋ค. ์ ํ ์กฐ๊ฑด strings๋ ๊ธธ์ด 1 ์ด์, 50์ดํ์ธ ๋ฐฐ์ด์ ๋๋ค. strings์ ์์๋ ์๋ฌธ์ ์ํ๋ฒณ์ผ๋ก ์ด๋ฃจ์ด์ ธ ์์ต๋๋ค. strings์ ์์๋ ๊ธธ์ด 1 ์ด์, 100์ดํ์ธ ๋ฌธ์์ด์ ๋๋ค. ๋ชจ๋ strings์ ์์์ ๊ธธ์ด๋ n๋ณด๋ค ํฝ๋๋ค. ์ธ๋ฑ์ค 1์ ๋ฌธ์๊ฐ ๊ฐ์ ๋ฌธ์์ด์ด ์ฌ๋ฟ ์ผ ๊ฒฝ์ฐ, ์ฌ์ ์์ผ๋ก ์์ ๋ฌธ์์ด์ด ์์ชฝ์ ์์นํฉ๋๋ค. ์ ์ถ๋ ฅ ์ strings n return ["sun", "b.. CodeKata/Programmers 2021. 11. 30. 0 [CK] ์ฐ์ต๋ฌธ์ > ์์ธ์์ ๊น์๋ฐฉ ์ฐพ๊ธฐ ๋ฌธ์ ์ค๋ช Stringํ ๋ฐฐ์ด seoul์ element ์ค "Kim"์ ์์น x๋ฅผ ์ฐพ์, "๊น์๋ฐฉ์ x์ ์๋ค"๋ String์ ๋ฐํํ๋ ํจ์, solution์ ์์ฑํ์ธ์. seoul์ "Kim"์ ์ค์ง ํ ๋ฒ๋ง ๋ํ๋๋ฉฐ ์๋ชป๋ ๊ฐ์ด ์ ๋ ฅ๋๋ ๊ฒฝ์ฐ๋ ์์ต๋๋ค. ์ ํ ์ฌํญ seoul์ ๊ธธ์ด 1 ์ด์, 1000 ์ดํ์ธ ๋ฐฐ์ด์ ๋๋ค. seoul์ ์์๋ ๊ธธ์ด 1 ์ด์, 20 ์ดํ์ธ ๋ฌธ์์ด์ ๋๋ค. "Kim"์ ๋ฐ๋์ seoul ์์ ํฌํจ๋์ด ์์ต๋๋ค. ์ ์ถ๋ ฅ ์ seoul return ["Jane", "Kim"] "๊น์๋ฐฉ์ 1์ ์๋ค" Solution #include #include using namespace std; string solution(vector seoul) { string answer = "๊น.. CodeKata/Programmers 2021. 11. 29. 0 [CK] ์ฐ์ต๋ฌธ์ > ์์ ์ฐพ๊ธฐ ๋ฌธ์ ์ค๋ช 1๋ถํฐ ์ ๋ ฅ๋ฐ์ ์ซ์ n ์ฌ์ด์ ์๋ ์์์ ๊ฐ์๋ฅผ ๋ฐํํ๋ ํจ์, solution์ ๋ง๋ค์ด ๋ณด์ธ์. ์์๋ 1๊ณผ ์๊ธฐ ์์ ์ผ๋ก๋ง ๋๋์ด์ง๋ ์๋ฅผ ์๋ฏธํฉ๋๋ค. (1์ ์์๊ฐ ์๋๋๋ค.) ์ ํ ์กฐ๊ฑด n์ 2์ด์ 1000000์ดํ์ ์์ฐ์์ ๋๋ค. ์ ์ถ๋ ฅ ์ n result 10 4 5 3 ์ ์ถ๋ ฅ ์ ์ค๋ช ์ ์ถ๋ ฅ ์ #1 1๋ถํฐ 10 ์ฌ์ด์ ์์๋ [2,3,5,7] 4๊ฐ๊ฐ ์กด์ฌํ๋ฏ๋ก 4๋ฅผ ๋ฐํ ์ ์ถ๋ ฅ ์ #2 1๋ถํฐ 5 ์ฌ์ด์ ์์๋ [2,3,5] 3๊ฐ๊ฐ ์กด์ฌํ๋ฏ๋ก 3์ ๋ฐํ Solution #include #include #include #include using namespace std; bool table[1000000] = {false,}; int solution(int n) { int an.. CodeKata/Programmers 2021. 11. 29. 0 [CK] ์ฐ์ต๋ฌธ์ > ์๋ฐ์๋ฐ์๋ฐ์๋ฐ์๋ฐ์? ๋ฌธ์ ์ค๋ช ๊ธธ์ด๊ฐ n์ด๊ณ , "์๋ฐ์๋ฐ์๋ฐ์...."์ ๊ฐ์ ํจํด์ ์ ์งํ๋ ๋ฌธ์์ด์ ๋ฆฌํดํ๋ ํจ์, solution์ ์์ฑํ์ธ์. ์๋ฅผ ๋ค์ด n์ด 4์ด๋ฉด "์๋ฐ์๋ฐ"์ ๋ฆฌํดํ๊ณ 3์ด๋ผ๋ฉด "์๋ฐ์"๋ฅผ ๋ฆฌํดํ๋ฉด ๋ฉ๋๋ค. ์ ํ ์กฐ๊ฑด n์ ๊ธธ์ด 10,000์ดํ์ธ ์์ฐ์์ ๋๋ค. ์ ์ถ๋ ฅ ์ n return 3 "์๋ฐ์" 4 "์๋ฐ์๋ฐ" Solution #include #include using namespace std; string solution(int n) { string answer = ""; bool bSu = true; for (int i = 0; i < n; i++) { if (bSu == true) { answer += "์"; } else { answer += "๋ฐ"; } bSu = !bSu; } r.. CodeKata/Programmers 2021. 11. 29. 0 [CK] ์ฐ์ต๋ฌธ์ > ๋ฌธ์์ด์ ์ ์๋ก ๋ฐ๊พธ๊ธฐ ๋ฌธ์ ์ค๋ช ๋ฌธ์์ด s๋ฅผ ์ซ์๋ก ๋ณํํ ๊ฒฐ๊ณผ๋ฅผ ๋ฐํํ๋ ํจ์, solution์ ์์ฑํ์ธ์. ์ ํ ์กฐ๊ฑด s์ ๊ธธ์ด๋ 1 ์ด์ 5์ดํ์ ๋๋ค. s์ ๋งจ์์๋ ๋ถํธ(+, -)๊ฐ ์ฌ ์ ์์ต๋๋ค. s๋ ๋ถํธ์ ์ซ์๋ก๋ง ์ด๋ฃจ์ด์ ธ์์ต๋๋ค. s๋ "0"์ผ๋ก ์์ํ์ง ์์ต๋๋ค. ์ ์ถ๋ ฅ ์ ์๋ฅผ ๋ค์ด str์ด "1234"์ด๋ฉด 1234๋ฅผ ๋ฐํํ๊ณ , "-1234"์ด๋ฉด -1234๋ฅผ ๋ฐํํ๋ฉด ๋ฉ๋๋ค. str์ ๋ถํธ(+,-)์ ์ซ์๋ก๋ง ๊ตฌ์ฑ๋์ด ์๊ณ , ์๋ชป๋ ๊ฐ์ด ์ ๋ ฅ๋๋ ๊ฒฝ์ฐ๋ ์์ต๋๋ค. Solution #include #include using namespace std; int solution(string s) { int plus = 1; if (s.at(0) == '-') { s.erase(s.begin()); plus *=.. CodeKata/Programmers 2021. 11. 29. 0 [CK] ์ฐ์ต๋ฌธ์ > ์์ ์ํธ ๋ฌธ์ ์ค๋ช ์ด๋ค ๋ฌธ์ฅ์ ๊ฐ ์ํ๋ฒณ์ ์ผ์ ํ ๊ฑฐ๋ฆฌ๋งํผ ๋ฐ์ด์ ๋ค๋ฅธ ์ํ๋ฒณ์ผ๋ก ๋ฐ๊พธ๋ ์ํธํ ๋ฐฉ์์ ์์ ์ํธ๋ผ๊ณ ํฉ๋๋ค. ์๋ฅผ ๋ค์ด "AB"๋ 1๋งํผ ๋ฐ๋ฉด "BC"๊ฐ ๋๊ณ , 3๋งํผ ๋ฐ๋ฉด "DE"๊ฐ ๋ฉ๋๋ค. "z"๋ 1๋งํผ ๋ฐ๋ฉด "a"๊ฐ ๋ฉ๋๋ค. ๋ฌธ์์ด s์ ๊ฑฐ๋ฆฌ n์ ์ ๋ ฅ๋ฐ์ s๋ฅผ n๋งํผ ๋ฏผ ์ํธ๋ฌธ์ ๋ง๋๋ ํจ์, solution์ ์์ฑํด ๋ณด์ธ์. ์ ํ ์กฐ๊ฑด ๊ณต๋ฐฑ์ ์๋ฌด๋ฆฌ ๋ฐ์ด๋ ๊ณต๋ฐฑ์ ๋๋ค. s๋ ์ํ๋ฒณ ์๋ฌธ์, ๋๋ฌธ์, ๊ณต๋ฐฑ์ผ๋ก๋ง ์ด๋ฃจ์ด์ ธ ์์ต๋๋ค. s์ ๊ธธ์ด๋ 8000์ดํ์ ๋๋ค. n์ 1 ์ด์, 25์ดํ์ธ ์์ฐ์์ ๋๋ค. ์ ์ถ๋ ฅ ์ s n result "AB" 1 "BC" "z" 1 "a" "a B z" 4 "e F d" Solution #include #include #include using name.. CodeKata/Programmers 2021. 11. 29. 0 [CK] ์ฐ์ต๋ฌธ์ > ์ฝ์์ ํฉ ๋ฌธ์ ์ค๋ช ์ ์ n์ ์ ๋ ฅ๋ฐ์ n์ ์ฝ์๋ฅผ ๋ชจ๋ ๋ํ ๊ฐ์ ๋ฆฌํดํ๋ ํจ์, solution์ ์์ฑํด์ฃผ์ธ์. ์ ํ ์ฌํญ n์ 0 ์ด์ 3000์ดํ์ธ ์ ์์ ๋๋ค. ์ ์ถ๋ ฅ ์ n return 12 28 5 6 ์ ์ถ๋ ฅ ์ ์ค๋ช ์ ์ถ๋ ฅ ์ #1 12์ ์ฝ์๋ 1, 2, 3, 4, 6, 12์ ๋๋ค. ์ด๋ฅผ ๋ชจ๋ ๋ํ๋ฉด 28์ ๋๋ค. ์ ์ถ๋ ฅ ์ #2 5์ ์ฝ์๋ 1, 5์ ๋๋ค. ์ด๋ฅผ ๋ชจ๋ ๋ํ๋ฉด 6์ ๋๋ค. Solution #include #include using namespace std; int solution(int n) { int answer = 0; for (int i = 1; i CodeKata/Programmers 2021. 11. 29. 0 [CK] ์ฐ์ต๋ฌธ์ > ๊ฐ์ ์ซ์๋ ์ซ์ด ๋ฌธ์ ์ค๋ช ๋ฐฐ์ด arr๊ฐ ์ฃผ์ด์ง๋๋ค. ๋ฐฐ์ด arr์ ๊ฐ ์์๋ ์ซ์ 0๋ถํฐ 9๊น์ง๋ก ์ด๋ฃจ์ด์ ธ ์์ต๋๋ค. ์ด๋, ๋ฐฐ์ด arr์์ ์ฐ์์ ์ผ๋ก ๋ํ๋๋ ์ซ์๋ ํ๋๋ง ๋จ๊ธฐ๊ณ ์ ๋ถ ์ ๊ฑฐํ๋ ค๊ณ ํฉ๋๋ค. ๋จ, ์ ๊ฑฐ๋ ํ ๋จ์ ์๋ค์ ๋ฐํํ ๋๋ ๋ฐฐ์ด arr์ ์์๋ค์ ์์๋ฅผ ์ ์งํด์ผ ํฉ๋๋ค. ์๋ฅผ ๋ค๋ฉด, arr = [1, 1, 3, 3, 0, 1, 1] ์ด๋ฉด [1, 3, 0, 1] ์ return ํฉ๋๋ค. arr = [4, 4, 4, 3, 3] ์ด๋ฉด [4, 3] ์ return ํฉ๋๋ค. ๋ฐฐ์ด arr์์ ์ฐ์์ ์ผ๋ก ๋ํ๋๋ ์ซ์๋ ์ ๊ฑฐํ๊ณ ๋จ์ ์๋ค์ return ํ๋ solution ํจ์๋ฅผ ์์ฑํด ์ฃผ์ธ์. ์ ํ์ฌํญ ๋ฐฐ์ด arr์ ํฌ๊ธฐ : 1,000,000 ์ดํ์ ์์ฐ์ ๋ฐฐ์ด arr์ ์์์ ํฌ๊ธฐ : 0๋ณด๋ค ํฌ๊ฑฐ๋ .. CodeKata/Programmers 2021. 11. 27. 0 [CK] ์ฐ์ต๋ฌธ์ > ์๋ฆฟ์ ๋ํ๊ธฐ ๋ฌธ์ ์ค๋ช ์์ฐ์ N์ด ์ฃผ์ด์ง๋ฉด, N์ ๊ฐ ์๋ฆฟ์์ ํฉ์ ๊ตฌํด์ return ํ๋ solution ํจ์๋ฅผ ๋ง๋ค์ด ์ฃผ์ธ์. ์๋ฅผ ๋ค์ด N = 123์ด๋ฉด 1 + 2 + 3 = 6์ return ํ๋ฉด ๋ฉ๋๋ค. ์ ํ์ฌํญ N์ ๋ฒ์ : 100,000,000 ์ดํ์ ์์ฐ์ ์ ์ถ๋ ฅ ์ N answer 123 6 987 24 ์ ์ถ๋ ฅ ์ ์ค๋ช ์ ์ถ๋ ฅ ์ #1 ๋ฌธ์ ์ ์์์ ๊ฐ์ต๋๋ค. ์ ์ถ๋ ฅ ์ #2 9 + 8 + 7 = 24์ด๋ฏ๋ก 24๋ฅผ return ํ๋ฉด ๋ฉ๋๋ค. Solution #include using namespace std; int solution(int n) { int answer = 0; while (0 < n) { answer += n % 10; n /= 10; } return answer; } ๋จ์ ์ฝ๋ .. CodeKata/Programmers 2021. 11. 27. 0 [CK] ์ฐ์ต๋ฌธ์ > ์์ฐ์ ๋ค์ง์ด ๋ฐฐ์ด๋ก ๋ง๋ค๊ธฐ ๋ฌธ์ ์ค๋ช ์์ฐ์ n์ ๋ค์ง์ด ๊ฐ ์๋ฆฌ ์ซ์๋ฅผ ์์๋ก ๊ฐ์ง๋ ๋ฐฐ์ด ํํ๋ก ๋ฆฌํดํด์ฃผ์ธ์. ์๋ฅผ ๋ค์ด n์ด 12345์ด๋ฉด [5,4,3,2,1]์ ๋ฆฌํดํฉ๋๋ค. ์ ํ ์กฐ๊ฑด n์ 10,000,000,000์ดํ์ธ ์์ฐ์์ ๋๋ค. ์ ์ถ๋ ฅ ์ n return 12345 [5,4,3,2,1] Solution #include #include using namespace std; vector solution(long long n) { vector answer; int _n = n; while (0 < n) { answer.push_back(n % 10); n /= 10; } return answer; } ํ๊ธฐ 200๋ช ์ด ๋๊ฒ ์ด๋ฐ ์์ผ๋ก ํ์๋๋ผ. (url: https://programmers.co.kr/learn/cours.. CodeKata/Programmers 2021. 11. 27. 0 [CK] ์ฐ์ต๋ฌธ์ > ์ ์ ๋ด๋ฆผ์ฐจ์์ผ๋ก ๋ฐฐ์นํ๊ธฐ ๋ฌธ์ ์ค๋ช ํจ์ solution์ ์ ์ n์ ๋งค๊ฐ๋ณ์๋ก ์ ๋ ฅ๋ฐ์ต๋๋ค. n์ ๊ฐ ์๋ฆฟ์๋ฅผ ํฐ ๊ฒ๋ถํฐ ์์ ์์ผ๋ก ์ ๋ ฌํ ์๋ก์ด ์ ์๋ฅผ ๋ฆฌํดํด์ฃผ์ธ์. ์๋ฅผ ๋ค์ด n์ด 118372๋ฉด 873211์ ๋ฆฌํดํ๋ฉด ๋ฉ๋๋ค. ์ ํ ์กฐ๊ฑด n์ 1์ด์ 8000000000 ์ดํ์ธ ์์ฐ์์ ๋๋ค. ์ ์ถ๋ ฅ ์ n return 118372 873211 Solution #include #include #include #include using namespace std; long long solution(long long n) { vector v; long long answer = 0; while (0 < n) { v.push_back(n % 10); n /= 10; } sort(v.begin(), v.end()); int srt = .. CodeKata/Programmers 2021. 11. 27. 0 [CK] ์ฐ์ต๋ฌธ์ > ์ ์ ์ ๊ณฑ๊ทผ ํ๋ณ ๋ฌธ์ ์ค๋ช ์์์ ์์ ์ ์ n์ ๋ํด, n์ด ์ด๋ค ์์ ์ ์ x์ ์ ๊ณฑ์ธ์ง ์๋์ง ํ๋จํ๋ ค ํฉ๋๋ค. n์ด ์์ ์ ์ x์ ์ ๊ณฑ์ด๋ผ๋ฉด x+1์ ์ ๊ณฑ์ ๋ฆฌํดํ๊ณ , n์ด ์์ ์ ์ x์ ์ ๊ณฑ์ด ์๋๋ผ๋ฉด -1์ ๋ฆฌํดํ๋ ํจ์๋ฅผ ์์ฑํ์ธ์. ์ ํ ์ฌํญ n์ 1์ด์, 50000000000000 ์ดํ์ธ ์์ ์ ์์ ๋๋ค. ์ ์ถ๋ ฅ ์ n return 121 144 3 -1 ์ ์ถ๋ ฅ ์ ์ค๋ช ์ ์ถ๋ ฅ ์#1 121์ ์์ ์ ์ 11์ ์ ๊ณฑ์ด๋ฏ๋ก, (11+1)๋ฅผ ์ ๊ณฑํ 144๋ฅผ ๋ฆฌํดํฉ๋๋ค. ์ ์ถ๋ ฅ ์#2 3์ ์์ ์ ์์ ์ ๊ณฑ์ด ์๋๋ฏ๋ก, -1์ ๋ฆฌํดํฉ๋๋ค. Solution #include #include #include using namespace std; long long solution(long long n) { lon.. CodeKata/Programmers 2021. 11. 27. 0 [CK] ์ฐ์ต๋ฌธ์ > ์ ์ผ ์์ ์ ์ ๊ฑฐํ๊ธฐ ๋ฌธ์ ์ค๋ช ์ ์๋ฅผ ์ ์ฅํ ๋ฐฐ์ด, arr์์ ๊ฐ์ฅ ์์ ์๋ฅผ ์ ๊ฑฐํ ๋ฐฐ์ด์ ๋ฆฌํดํ๋ ํจ์, solution์ ์์ฑํด์ฃผ์ธ์. ๋จ, ๋ฆฌํดํ๋ ค๋ ๋ฐฐ์ด์ด ๋น ๋ฐฐ์ด์ธ ๊ฒฝ์ฐ์ ๋ฐฐ์ด์ -1์ ์ฑ์ ๋ฆฌํดํ์ธ์. ์๋ฅผ ๋ค์ด arr์ด [4,3,2,1]์ธ ๊ฒฝ์ฐ๋ [4,3,2]๋ฅผ ๋ฆฌํดํ๊ณ , [10] ๋ฉด [-1]์ ๋ฆฌํดํฉ๋๋ค. ์ ํ ์กฐ๊ฑด arr์ ๊ธธ์ด 1 ์ด์์ธ ๋ฐฐ์ด์ ๋๋ค. ์ธ๋ฑ์ค i, j์ ๋ํด i โ j์ด๋ฉด arr[i] โ arr[j] ์ ๋๋ค. ์ ์ถ๋ ฅ ์ arr return [4,3,2,1] [4,3,2] [10] [-1] Solution #include #include #include using namespace std; vector solution(vector arr) { vector answer(arr); int min.. CodeKata/Programmers 2021. 11. 27. 0 [CK] ์ฐ์ต๋ฌธ์ > ์ง์์ ํ์ ๋ฌธ์ ์ค๋ช ์ ์ num์ด ์ง์์ผ ๊ฒฝ์ฐ "Even"์ ๋ฐํํ๊ณ ํ์์ธ ๊ฒฝ์ฐ "Odd"๋ฅผ ๋ฐํํ๋ ํจ์, solution์ ์์ฑํด์ฃผ์ธ์. ์ ํ ์กฐ๊ฑด num์ int ๋ฒ์์ ์ ์์ ๋๋ค. 0์ ์ง์์ ๋๋ค. ์ ์ถ๋ ฅ ์ num return 3 "Odd" 4 "Even" Solution #include #include using namespace std; string solution(int num) { return num & 1 == 1 ? "Odd" : "Even"; } ํ๊ธฐ ํ ์ง ๊ฐ๋ ค๋ด๊ธฐ์ ์ ์: & 1 (url: https://programmers.co.kr/learn/courses/30/lessons/12937) CodeKata/Programmers 2021. 11. 27. 0 [CK] ์ฐ์ต๋ฌธ์ > ์ต๋๊ณต์ฝ์์ ์ต์๊ณต๋ฐฐ์ ๋ฌธ์ ์ค๋ช ๋ ์๋ฅผ ์ ๋ ฅ๋ฐ์ ๋ ์์ ์ต๋๊ณต์ฝ์์ ์ต์๊ณต๋ฐฐ์๋ฅผ ๋ฐํํ๋ ํจ์, solution์ ์์ฑํด ๋ณด์ธ์. ๋ฐฐ์ด์ ๋งจ ์์ ์ต๋๊ณต์ฝ์, ๊ทธ๋ค์ ์ต์๊ณต๋ฐฐ์๋ฅผ ๋ฃ์ด ๋ฐํํ๋ฉด ๋ฉ๋๋ค. ์๋ฅผ ๋ค์ด ๋ ์ 3, 12์ ์ต๋๊ณต์ฝ์๋ 3, ์ต์๊ณต๋ฐฐ์๋ 12์ด๋ฏ๋ก solution(3, 12)๋ [3, 12]๋ฅผ ๋ฐํํด์ผ ํฉ๋๋ค. ์ ํ ์ฌํญ ๋ ์๋ 1์ด์ 1000000์ดํ์ ์์ฐ์์ ๋๋ค. ์ ์ถ๋ ฅ ์ n m return 3 12 [3, 12] 2 5 [1, 10] ์ ์ถ๋ ฅ ์ ์ค๋ช ์ ์ถ๋ ฅ ์ #1 ์์ ์ค๋ช ๊ณผ ๊ฐ์ต๋๋ค. ์ ์ถ๋ ฅ ์ #2 ์์ฐ์ 2์ 5์ ์ต๋๊ณต์ฝ์๋ 1, ์ต์๊ณต๋ฐฐ์๋ 10์ด๋ฏ๋ก [1, 10]์ ๋ฆฌํดํด์ผ ํฉ๋๋ค. Solution #include #include using namespace std; int.. CodeKata/Programmers 2021. 11. 27. 0 [CK] ์ฐ์ต๋ฌธ์ > ์ฝ๋ผ์ธ ์ถ์ธก ๋ฌธ์ ์ค๋ช 1937๋ Collatz๋ ์ฌ๋์ ์ํด ์ ๊ธฐ๋ ์ด ์ถ์ธก์, ์ฃผ์ด์ง ์๊ฐ 1์ด ๋ ๋๊น์ง ๋ค์ ์์ ์ ๋ฐ๋ณตํ๋ฉด, ๋ชจ๋ ์๋ฅผ 1๋ก ๋ง๋ค ์ ์๋ค๋ ์ถ์ธก์ ๋๋ค. ์์ ์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค. 1-1. ์ ๋ ฅ๋ ์๊ฐ ์ง์๋ผ๋ฉด 2๋ก ๋๋๋๋ค. 1-2. ์ ๋ ฅ๋ ์๊ฐ ํ์๋ผ๋ฉด 3์ ๊ณฑํ๊ณ 1์ ๋ํฉ๋๋ค. 2. ๊ฒฐ๊ณผ๋ก ๋์จ ์์ ๊ฐ์ ์์ ์ 1์ด ๋ ๋๊น์ง ๋ฐ๋ณตํฉ๋๋ค. ์๋ฅผ ๋ค์ด, ์ ๋ ฅ๋ ์๊ฐ 6์ด๋ผ๋ฉด 6โ3โ10โ5โ16โ8โ4โ2โ1 ์ด ๋์ด ์ด 8๋ฒ ๋ง์ 1์ด ๋ฉ๋๋ค. ์ ์์ ์ ๋ช ๋ฒ์ด๋ ๋ฐ๋ณตํด์ผ ํ๋์ง ๋ฐํํ๋ ํจ์, solution์ ์์ฑํด ์ฃผ์ธ์. ๋จ, ์์ ์ 500๋ฒ์ ๋ฐ๋ณตํด๋ 1์ด ๋์ง ์๋๋ค๋ฉด โ1์ ๋ฐํํด ์ฃผ์ธ์. ์ ํ ์ฌํญ ์ ๋ ฅ๋ ์, num์ 1 ์ด์ 8000000 ๋ฏธ๋ง์ธ ์ ์์ ๋๋ค. ์ ์ถ๋ ฅ.. CodeKata/Programmers 2021. 11. 27. 0 [CK] ์ฐ์ต๋ฌธ์ > ํ๊ท ๊ตฌํ๊ธฐ ๋ฌธ์ ์ค๋ช ์ ์๋ฅผ ๋ด๊ณ ์๋ ๋ฐฐ์ด arr์ ํ๊ท ๊ฐ์ return ํ๋ ํจ์, solution์ ์์ฑํด๋ณด์ธ์. ์ ํ์ฌํญ arr์ ๊ธธ์ด 1 ์ด์, 100 ์ดํ์ธ ๋ฐฐ์ด์ ๋๋ค. arr์ ์์๋ -10,000 ์ด์ 10,000 ์ดํ์ธ ์ ์์ ๋๋ค. ์ ์ถ๋ ฅ ์ arr return [1,2,3,4] 2.5 [5,5] 5 Solution #include #include using namespace std; double solution(vector arr) { double answer = 0; for (auto x : arr) { answer += x; } return answer / arr.size(); } ๋จ์ ์ฝ๋ #include #include #include using namespace std; double so.. CodeKata/Programmers 2021. 11. 27. 0 ์ด์ 1 2 3 ๋ค์