From 00874bfb3c3e6f511dfce0262d54b379a700bfa8 Mon Sep 17 00:00:00 2001 From: lee0802-120 Date: Mon, 20 Jul 2026 10:43:12 +0900 Subject: [PATCH] =?UTF-8?q?=EC=9D=B4=EC=A4=80=EC=84=9D=20=EC=A0=9C?= =?UTF-8?q?=EC=B6=9C=ED=95=A9=EB=8B=88=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../solution.test.ts" | 16 ++++++++++ .../solution.ts" | 24 ++++++++++++++ .../solution.test.ts" | 24 ++++++++++++++ .../solution.ts" | 11 +++++++ .../solution.test.ts" | 16 ++++++++++ .../solution.ts" | 11 +++++++ .../solution.test.ts" | 31 +++++++++++++++++++ .../solution.ts" | 12 +++++++ .../solution.test.ts" | 20 ++++++++++++ .../solution.ts" | 13 ++++++++ .../solution.test.ts" | 20 ++++++++++++ .../solution.ts" | 17 ++++++++++ .../solution.test.ts" | 16 ++++++++++ .../solution.ts" | 22 +++++++++++++ .../solution.test.ts" | 16 ++++++++++ .../solution.ts" | 17 ++++++++++ 16 files changed, 286 insertions(+) create mode 100644 "level-01/1.1-\354\202\254\354\271\231\354\227\260\354\202\260/solution.test.ts" create mode 100644 "level-01/1.1-\354\202\254\354\271\231\354\227\260\354\202\260/solution.ts" create mode 100644 "level-01/1.2-\355\231\200\354\247\235\355\214\220\353\263\204/solution.test.ts" create mode 100644 "level-01/1.2-\355\231\200\354\247\235\355\214\220\353\263\204/solution.ts" create mode 100644 "level-01/1.3-\354\204\270\354\210\230\354\265\234\353\214\223\352\260\222/solution.test.ts" create mode 100644 "level-01/1.3-\354\204\270\354\210\230\354\265\234\353\214\223\352\260\222/solution.ts" create mode 100644 "level-01/1.4-\354\240\220\354\210\230\353\223\261\352\270\211/solution.test.ts" create mode 100644 "level-01/1.4-\354\240\220\354\210\230\353\223\261\352\270\211/solution.ts" create mode 100644 "level-01/1.5-\354\234\244\353\205\204\355\214\220\353\263\204/solution.test.ts" create mode 100644 "level-01/1.5-\354\234\244\353\205\204\355\214\220\353\263\204/solution.ts" create mode 100644 "level-01/1.6-\354\264\210\353\245\274\354\213\234\353\266\204\354\264\210\353\241\234/solution.test.ts" create mode 100644 "level-01/1.6-\354\264\210\353\245\274\354\213\234\353\266\204\354\264\210\353\241\234/solution.ts" create mode 100644 "level-01/1.7-\353\266\200\355\230\270\353\266\204\353\245\230/solution.test.ts" create mode 100644 "level-01/1.7-\353\266\200\355\230\270\353\266\204\353\245\230/solution.ts" create mode 100644 "level-01/1.8-\354\240\210\353\214\223\352\260\222\355\225\251/solution.test.ts" create mode 100644 "level-01/1.8-\354\240\210\353\214\223\352\260\222\355\225\251/solution.ts" diff --git "a/level-01/1.1-\354\202\254\354\271\231\354\227\260\354\202\260/solution.test.ts" "b/level-01/1.1-\354\202\254\354\271\231\354\227\260\354\202\260/solution.test.ts" new file mode 100644 index 0000000..e544457 --- /dev/null +++ "b/level-01/1.1-\354\202\254\354\271\231\354\227\260\354\202\260/solution.test.ts" @@ -0,0 +1,16 @@ +import { describe, it, expect } from "vitest"; +import { solution } from "./solution"; + +describe("1.1 사칙연산", () => { + it("기본 사칙연산", () => { + expect(solution(7, 2)).toEqual({ add: 9, sub: 5, mul: 14, div: 3 }); + }); + + it("음수가 섞인 경우 몫은 0 방향으로 버린다", () => { + expect(solution(-7, 2)).toEqual({ add: -5, sub: -9, mul: -14, div: -3 }); + }); + + it("나누어떨어지는 경우", () => { + expect(solution(10, 5)).toEqual({ add: 15, sub: 5, mul: 50, div: 2 }); + }); +}); diff --git "a/level-01/1.1-\354\202\254\354\271\231\354\227\260\354\202\260/solution.ts" "b/level-01/1.1-\354\202\254\354\271\231\354\227\260\354\202\260/solution.ts" new file mode 100644 index 0000000..7b1fbb3 --- /dev/null +++ "b/level-01/1.1-\354\202\254\354\271\231\354\227\260\354\202\260/solution.ts" @@ -0,0 +1,24 @@ +/** + * 1.1 사칙연산 [프로그래머스 Lv0 / 백준 Bronze V] + * + * 두 정수 a, b의 합(add)·차(sub)·곱(mul)·몫(div)을 객체로 반환하세요. + * 몫은 0 방향으로 버림한 정수입니다. b는 0이 아님이 보장됩니다. + * + * @example + * solution(7, 2) // => { add: 9, sub: 5, mul: 14, div: 3 } + */ +export interface ArithmeticResult { + add: number; + sub: number; + mul: number; + div: number; +} + +export function solution(a: number, b: number): ArithmeticResult { + return { + add: a + b, + sub: a - b, + mul: a * b, + div: Math.trunc(a / b) + } +} diff --git "a/level-01/1.2-\355\231\200\354\247\235\355\214\220\353\263\204/solution.test.ts" "b/level-01/1.2-\355\231\200\354\247\235\355\214\220\353\263\204/solution.test.ts" new file mode 100644 index 0000000..2aaa447 --- /dev/null +++ "b/level-01/1.2-\355\231\200\354\247\235\355\214\220\353\263\204/solution.test.ts" @@ -0,0 +1,24 @@ +import { describe, it, expect } from "vitest"; +import { solution } from "./solution"; + +describe("1.2 홀짝 판별", () => { + it("홀수를 판별한다", () => { + expect(solution(3)).toBe("홀수"); + }); + + it("짝수를 판별한다", () => { + expect(solution(4)).toBe("짝수"); + }); + + it("0은 짝수로 판별한다", () => { + expect(solution(0)).toBe("짝수"); + }); + + it("음수 홀수도 판별한다", () => { + expect(solution(-7)).toBe("홀수"); + }); + + it("음수 짝수도 판별한다", () => { + expect(solution(-4)).toBe("짝수"); + }); +}); diff --git "a/level-01/1.2-\355\231\200\354\247\235\355\214\220\353\263\204/solution.ts" "b/level-01/1.2-\355\231\200\354\247\235\355\214\220\353\263\204/solution.ts" new file mode 100644 index 0000000..946dc11 --- /dev/null +++ "b/level-01/1.2-\355\231\200\354\247\235\355\214\220\353\263\204/solution.ts" @@ -0,0 +1,11 @@ +/** + * 1.2 홀짝 판별 [프로그래머스 Lv0 / 백준 Bronze V] + * + * 정수 n이 홀수면 "홀수", 짝수면 "짝수"를 반환하세요. (0은 짝수) + * + * @example + * solution(3) // => "홀수" + */ +export function solution(n: number): "홀수" | "짝수" { + return n % 2 === 0 ? "짝수" : "홀수"; +} diff --git "a/level-01/1.3-\354\204\270\354\210\230\354\265\234\353\214\223\352\260\222/solution.test.ts" "b/level-01/1.3-\354\204\270\354\210\230\354\265\234\353\214\223\352\260\222/solution.test.ts" new file mode 100644 index 0000000..c64a404 --- /dev/null +++ "b/level-01/1.3-\354\204\270\354\210\230\354\265\234\353\214\223\352\260\222/solution.test.ts" @@ -0,0 +1,16 @@ +import { describe, it, expect } from "vitest"; +import { solution } from "./solution"; + +describe("1.3 세 수의 최댓값", () => { + it("일반적인 경우", () => { + expect(solution(3, 7, 5)).toBe(7); + }); + + it("모두 음수", () => { + expect(solution(-1, -9, -3)).toBe(-1); + }); + + it("같은 값이 섞인 경우", () => { + expect(solution(5, 5, 2)).toBe(5); + }); +}); diff --git "a/level-01/1.3-\354\204\270\354\210\230\354\265\234\353\214\223\352\260\222/solution.ts" "b/level-01/1.3-\354\204\270\354\210\230\354\265\234\353\214\223\352\260\222/solution.ts" new file mode 100644 index 0000000..77e3ca8 --- /dev/null +++ "b/level-01/1.3-\354\204\270\354\210\230\354\265\234\353\214\223\352\260\222/solution.ts" @@ -0,0 +1,11 @@ +/** + * 1.3 세 수의 최댓값 [프로그래머스 Lv0 / 백준 Bronze V] + * + * 세 정수 a, b, c 중 가장 큰 값을 반환하세요. + * + * @example + * solution(3, 7, 5) // => 7 + */ +export function solution(a: number, b: number, c: number): number { + return Math.max(...[a, b, c]); +} diff --git "a/level-01/1.4-\354\240\220\354\210\230\353\223\261\352\270\211/solution.test.ts" "b/level-01/1.4-\354\240\220\354\210\230\353\223\261\352\270\211/solution.test.ts" new file mode 100644 index 0000000..6d48e7b --- /dev/null +++ "b/level-01/1.4-\354\240\220\354\210\230\353\223\261\352\270\211/solution.test.ts" @@ -0,0 +1,31 @@ +import { describe, it, expect } from "vitest"; +import { solution } from "./solution"; + +describe("1.4 점수 등급", () => { + it("구간 가운데 점수의 등급을 반환한다", () => { + expect(solution(95)).toBe("A"); + expect(solution(85)).toBe("B"); + expect(solution(73)).toBe("C"); + expect(solution(65)).toBe("D"); + expect(solution(40)).toBe("F"); + }); + + it("경계값은 위 등급에 속한다", () => { + expect(solution(90)).toBe("A"); + expect(solution(80)).toBe("B"); + expect(solution(70)).toBe("C"); + expect(solution(60)).toBe("D"); + }); + + it("경계 바로 아래는 아래 등급에 속한다", () => { + expect(solution(89)).toBe("B"); + expect(solution(79)).toBe("C"); + expect(solution(69)).toBe("D"); + expect(solution(59)).toBe("F"); + }); + + it("최고점 100은 A, 최저점 0은 F다", () => { + expect(solution(100)).toBe("A"); + expect(solution(0)).toBe("F"); + }); +}); diff --git "a/level-01/1.4-\354\240\220\354\210\230\353\223\261\352\270\211/solution.ts" "b/level-01/1.4-\354\240\220\354\210\230\353\223\261\352\270\211/solution.ts" new file mode 100644 index 0000000..7b71318 --- /dev/null +++ "b/level-01/1.4-\354\240\220\354\210\230\353\223\261\352\270\211/solution.ts" @@ -0,0 +1,12 @@ +/** + * 1.4 점수 등급 [프로그래머스 Lv0 / 백준 Bronze V] + * + * 시험 점수(0~100)를 받아 등급을 반환하세요. + * 90 이상 "A", 80 이상 "B", 70 이상 "C", 60 이상 "D", 그 외 "F"입니다. + * + * @example + * solution(73) // => "C" + */ +export function solution(score: number): "A" | "B" | "C" | "D" | "F" { + return score >= 90 ? "A" : score >= 80 ? "B" : score >= 70 ? "C" : score >= 60 ? "D" : "F" +} diff --git "a/level-01/1.5-\354\234\244\353\205\204\355\214\220\353\263\204/solution.test.ts" "b/level-01/1.5-\354\234\244\353\205\204\355\214\220\353\263\204/solution.test.ts" new file mode 100644 index 0000000..31aede7 --- /dev/null +++ "b/level-01/1.5-\354\234\244\353\205\204\355\214\220\353\263\204/solution.test.ts" @@ -0,0 +1,20 @@ +import { describe, it, expect } from "vitest"; +import { solution } from "./solution"; + +describe("1.5 윤년 판별", () => { + it("400의 배수는 윤년", () => { + expect(solution(2000)).toBe(true); + }); + + it("100의 배수지만 400의 배수가 아니면 평년", () => { + expect(solution(1900)).toBe(false); + }); + + it("4의 배수 윤년", () => { + expect(solution(2024)).toBe(true); + }); + + it("4의 배수가 아니면 평년", () => { + expect(solution(2023)).toBe(false); + }); +}); diff --git "a/level-01/1.5-\354\234\244\353\205\204\355\214\220\353\263\204/solution.ts" "b/level-01/1.5-\354\234\244\353\205\204\355\214\220\353\263\204/solution.ts" new file mode 100644 index 0000000..5311dba --- /dev/null +++ "b/level-01/1.5-\354\234\244\353\205\204\355\214\220\353\263\204/solution.ts" @@ -0,0 +1,13 @@ +/** + * 1.5 윤년 판별 [프로그래머스 Lv0 / 백준 Bronze V] + * + * 연도 year가 윤년이면 true, 아니면 false를 반환하세요. + * 윤년은 4의 배수이면서, 100의 배수가 아니거나 400의 배수인 해입니다. + * + * @example + * solution(2024) // => true + * solution(1900) // => false + */ +export function solution(year: number): boolean { + return new Date(year, 2, 0).getDate() === 29; +} diff --git "a/level-01/1.6-\354\264\210\353\245\274\354\213\234\353\266\204\354\264\210\353\241\234/solution.test.ts" "b/level-01/1.6-\354\264\210\353\245\274\354\213\234\353\266\204\354\264\210\353\241\234/solution.test.ts" new file mode 100644 index 0000000..0f274c4 --- /dev/null +++ "b/level-01/1.6-\354\264\210\353\245\274\354\213\234\353\266\204\354\264\210\353\241\234/solution.test.ts" @@ -0,0 +1,20 @@ +import { describe, it, expect } from "vitest"; +import { solution } from "./solution"; + +describe("1.6 초를 시:분:초로", () => { + it("3661초", () => { + expect(solution(3661)).toBe("01:01:01"); + }); + + it("0을 두 자리로 채운다", () => { + expect(solution(59)).toBe("00:00:59"); + }); + + it("0초", () => { + expect(solution(0)).toBe("00:00:00"); + }); + + it("24시간을 넘어가는 경우", () => { + expect(solution(90000)).toBe("25:00:00"); + }); +}); diff --git "a/level-01/1.6-\354\264\210\353\245\274\354\213\234\353\266\204\354\264\210\353\241\234/solution.ts" "b/level-01/1.6-\354\264\210\353\245\274\354\213\234\353\266\204\354\264\210\353\241\234/solution.ts" new file mode 100644 index 0000000..65c0aa7 --- /dev/null +++ "b/level-01/1.6-\354\264\210\353\245\274\354\213\234\353\266\204\354\264\210\353\241\234/solution.ts" @@ -0,0 +1,17 @@ +/** + * 1.6 초를 시:분:초로 [프로그래머스 Lv0 / 백준 Bronze IV] + * + * 0 이상의 정수 sec(초)를 "HH:MM:SS" 형식 문자열로 반환하세요. + * 시·분·초는 항상 두 자리로 0을 채우고, 시는 24를 넘어갈 수 있습니다. + * + * @example + * solution(3661) // => "01:01:01" + */ +export function solution(sec: number): string { + const HH = Math.floor(sec / 3600); + const MM = Math.floor((sec % 3600) / 60); + const SS = sec % 60; + const pad = (num :any) => String(num).padStart(2, "0"); + + return `${pad(HH)}:${pad(MM)}:${pad(SS)}`; +} diff --git "a/level-01/1.7-\353\266\200\355\230\270\353\266\204\353\245\230/solution.test.ts" "b/level-01/1.7-\353\266\200\355\230\270\353\266\204\353\245\230/solution.test.ts" new file mode 100644 index 0000000..2961443 --- /dev/null +++ "b/level-01/1.7-\353\266\200\355\230\270\353\266\204\353\245\230/solution.test.ts" @@ -0,0 +1,16 @@ +import { describe, it, expect } from "vitest"; +import { solution } from "./solution"; + +describe("1.7 부호 분류", () => { + it("양수/음수/0을 센다", () => { + expect(solution([1, -2, 0, 3, 0, -5])).toEqual({ + positive: 2, + negative: 2, + zero: 2, + }); + }); + + it("빈 배열은 모두 0", () => { + expect(solution([])).toEqual({ positive: 0, negative: 0, zero: 0 }); + }); +}); diff --git "a/level-01/1.7-\353\266\200\355\230\270\353\266\204\353\245\230/solution.ts" "b/level-01/1.7-\353\266\200\355\230\270\353\266\204\353\245\230/solution.ts" new file mode 100644 index 0000000..3977dd8 --- /dev/null +++ "b/level-01/1.7-\353\266\200\355\230\270\353\266\204\353\245\230/solution.ts" @@ -0,0 +1,22 @@ +/** + * 1.7 부호 분류 [프로그래머스 Lv0 / 백준 Bronze IV] + * + * 정수 배열을 받아 양수·음수·0의 개수를 객체로 반환하세요. + * + * @example + * solution([1, -2, 0, 3, 0, -5]) + * // => { positive: 2, negative: 2, zero: 2 } + */ +export interface SignCount { + positive: number; + negative: number; + zero: number; +} + +export function solution(numbers: number[]): SignCount { + return { + positive: numbers.filter(x => x > 0).length, + negative: numbers.filter(x => x < 0).length, + zero: numbers.filter(x => x === 0).length + } +} diff --git "a/level-01/1.8-\354\240\210\353\214\223\352\260\222\355\225\251/solution.test.ts" "b/level-01/1.8-\354\240\210\353\214\223\352\260\222\355\225\251/solution.test.ts" new file mode 100644 index 0000000..9e90725 --- /dev/null +++ "b/level-01/1.8-\354\240\210\353\214\223\352\260\222\355\225\251/solution.test.ts" @@ -0,0 +1,16 @@ +import { describe, it, expect } from "vitest"; +import { solution } from "./solution"; + +describe("1.8 절댓값의 합", () => { + it("음수의 절댓값을 더한다", () => { + expect(solution([-3, 4, -1])).toBe(8); + }); + + it("빈 배열은 0", () => { + expect(solution([])).toBe(0); + }); + + it("모두 양수", () => { + expect(solution([1, 2, 3])).toBe(6); + }); +}); diff --git "a/level-01/1.8-\354\240\210\353\214\223\352\260\222\355\225\251/solution.ts" "b/level-01/1.8-\354\240\210\353\214\223\352\260\222\355\225\251/solution.ts" new file mode 100644 index 0000000..deba77a --- /dev/null +++ "b/level-01/1.8-\354\240\210\353\214\223\352\260\222\355\225\251/solution.ts" @@ -0,0 +1,17 @@ +/** + * 1.8 절댓값의 합 [프로그래머스 Lv0 / 백준 Bronze IV] + * + * 정수 배열을 받아 각 원소의 절댓값을 모두 더한 값을 반환하세요. + * + * @example + * solution([-3, 4, -1]) // => 8 + */ +export function solution(numbers: number[]): number { + let num = 0; + for (let i = 0; i < numbers.length; i++) { + const num2 = Math.abs(numbers[i]); + num += num2; + } + + return num +}