From 03269a0ad37fbe159eac5947cb14b9d7fce0f9d4 Mon Sep 17 00:00:00 2001 From: SEAN-59 Date: Fri, 17 Oct 2025 00:17:22 +0900 Subject: [PATCH] =?UTF-8?q?=EA=B3=B5=EB=B6=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 2문제 풀었음 --- README.md | 20 ++++----- .../Test_Coding_Swift/Hash/Clothes.swift | 21 ++++++++++ .../Test_Coding_Swift/Hash/Hash.md | 6 +++ .../Stack&Queue/FuncDev.swift | 41 +++++++++++++++++++ .../Test_Coding_Swift/main.swift | 7 +++- 5 files changed, 84 insertions(+), 11 deletions(-) create mode 100644 Test_Coding_Swift/Test_Coding_Swift/Hash/Clothes.swift create mode 100644 Test_Coding_Swift/Test_Coding_Swift/Hash/Hash.md create mode 100644 Test_Coding_Swift/Test_Coding_Swift/Stack&Queue/FuncDev.swift diff --git a/README.md b/README.md index a0686d3..f401341 100644 --- a/README.md +++ b/README.md @@ -2,15 +2,15 @@ [프로그래머스 코딩테스트 고득점 Kit](https://school.programmers.co.kr/learn/challenges?tab=algorithm_practice_kit). -1. 해시 (5문항) -2. 스택 / 큐 (6문항) -3. 힙 (3문항) -4. 정렬 (3문항) -5. 완전탐색 (7문항) -6. Greeedy (6문항) -7. DP (5문항) -8. DFS / BFS (7문항) -9. B-Search (2문항) -10. Graph (3문항) +1. 해시 (5문항) S: 2 / P: 5 +2. 스택 / 큐 (6문항) S: 4 / P: 6 +3. 힙 (3문항) S: / P: +4. 정렬 (3문항) S: / P: +5. 완전탐색 (7문항) S: / P: +6. Greeedy (6문항) S: / P: +7. DP (5문항) S: / P: +8. DFS / BFS (7문항) S: / P: +9. B-Search (2문항) S: / P: +10. Graph (3문항) S: / P: - 각각 Swift와 Python으로 풀어볼 것이며 Swift로 먼저 풀이를 진행한다. diff --git a/Test_Coding_Swift/Test_Coding_Swift/Hash/Clothes.swift b/Test_Coding_Swift/Test_Coding_Swift/Hash/Clothes.swift new file mode 100644 index 0000000..7c30753 --- /dev/null +++ b/Test_Coding_Swift/Test_Coding_Swift/Hash/Clothes.swift @@ -0,0 +1,21 @@ +// +// Clothes.swift +// Test_Coding_Swift +// +// Created by Sean Kim on 10/16/25. +// + +import Foundation +/// 키워드 +/// 매일 다른 옷 조합 +/// [의상의 이름, 의상의 종류] +/// 중복되지 않는 각 요소들의 조합 + +func clothesSolution(_ clothes:[[String]]) -> Int { + var clothesDict: [String: Int] = [:] + for cloth in clothes {clothesDict[cloth[1], default: 0] += 1} + let combination = clothesDict.values.reduce(1) {$0 * ($1 + 1)} + return combination - 1 +} + + diff --git a/Test_Coding_Swift/Test_Coding_Swift/Hash/Hash.md b/Test_Coding_Swift/Test_Coding_Swift/Hash/Hash.md new file mode 100644 index 0000000..29adfa2 --- /dev/null +++ b/Test_Coding_Swift/Test_Coding_Swift/Hash/Hash.md @@ -0,0 +1,6 @@ +# Hash? +- Hash 는 Key를 사용하여 해시함수를 통해 해시를 하고 그 결과 값인 주소 값에 해당하는 테이블 슬롯에 value를 저장하는 것이다. +- 해시 테이블은 배열로 이루어져 있다. (딕셔너리의 경우 값이 없으면 nil 리턴이니 이 부분으로 초기화도 잊지 말것) +- 해시 함수는 뭐 따로 있겠지만 해시 함수를 따로 사용하는 것도 좋음 +- 해시 테이블 저장을 위해서는 k-v 쌍을 받아야 하고 이를 해시 테이블에 저장만 하면 된다. + diff --git a/Test_Coding_Swift/Test_Coding_Swift/Stack&Queue/FuncDev.swift b/Test_Coding_Swift/Test_Coding_Swift/Stack&Queue/FuncDev.swift new file mode 100644 index 0000000..52a4ab8 --- /dev/null +++ b/Test_Coding_Swift/Test_Coding_Swift/Stack&Queue/FuncDev.swift @@ -0,0 +1,41 @@ +// +// FuncDev.swift +// Test_Coding_Swift +// +// Created by Sean Kim on 10/16/25. +// + +import Foundation + +/// 키워드 +/// 개발 속도 다름, 앞보다 먼저 개발 가능. but 뒤에있는건 앞에 있는게 배포 될때 배포 +/// +func solution(_ progresses:[Int], _ speeds:[Int]) -> [Int] { + var speedCheck = [Int]() + var resultCount = [Int]() + var count = 0 + var checkNum = -1 + + for i in 0 ..< progresses.count { + var checkNum = 100 - progresses[i] + var processDay = checkNum / speeds[i] + (checkNum % speeds[i] > 0 ? 1 : 0) + speedCheck.append(processDay) + } + + speedCheck.forEach {speed in + if checkNum == -1 { + checkNum = speed + count += 1 + } else if checkNum >= speed { + count += 1 + } + if checkNum < speed { + resultCount.append(count) + count = 1 + checkNum = speed + } + } + resultCount.append(count) + + return resultCount +} diff --git a/Test_Coding_Swift/Test_Coding_Swift/main.swift b/Test_Coding_Swift/Test_Coding_Swift/main.swift index 8e34206..6d8b639 100644 --- a/Test_Coding_Swift/Test_Coding_Swift/main.swift +++ b/Test_Coding_Swift/Test_Coding_Swift/main.swift @@ -7,5 +7,10 @@ import Foundation -print("Hello, World!") +var result = solution([93, 30, 55],[1, 30, 5]) +//var result = solution([95, 90, 99, 99, 80, 99],[1, 1, 1, 1, 1, 1]) +//var result = solution([94,95,90],[4,3,1]) + + +print(result)