Skip to content

Commit

Permalink
#23 - 실패율 문제 풀이
Browse files Browse the repository at this point in the history
  • Loading branch information
hwangJi-dev committed Oct 11, 2022
1 parent c5c3a07 commit d394305
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 0 deletions.
Binary file added .DS_Store
Binary file not shown.
8 changes: 8 additions & 0 deletions Programmers/Programmers.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
3341499A2897EA4D008BB719 /* otherSolve.swift in Sources */ = {isa = PBXBuildFile; fileRef = 334149992897EA4D008BB719 /* otherSolve.swift */; };
334E6FEB28DE126E00865FDD /* 양과 늑대.swift in Sources */ = {isa = PBXBuildFile; fileRef = 334E6FEA28DE126E00865FDD /* 양과 늑대.swift */; };
334E6FED28DE326200865FDD /* 파괴되지 않은 건물.swift in Sources */ = {isa = PBXBuildFile; fileRef = 334E6FEC28DE326200865FDD /* 파괴되지 않은 건물.swift */; };
334E6FEF28DE344700865FDD /* 신고 결과 받기.swift in Sources */ = {isa = PBXBuildFile; fileRef = 334E6FEE28DE344700865FDD /* 신고 결과 받기.swift */; };
33A5DAF828D9C3AB00E4EB37 /* 큰 수 만들기.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33A5DAF728D9C3AB00E4EB37 /* 큰 수 만들기.swift */; };
33AE9BCB28F58A470081D069 /* 실패율.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33AE9BCA28F58A470081D069 /* 실패율.swift */; };
33B39B2B289C4C2D0065B484 /* 타겟 넘버.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33B39B2A289C4C2D0065B484 /* 타겟 넘버.swift */; };
33CB361D28DDEF56009BEB59 /* 메뉴 리뉴얼.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33CB361C28DDEF56009BEB59 /* 메뉴 리뉴얼.swift */; };
33CEFA5B28DA4057007CDBBB /* 괄호 변환.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33CEFA5A28DA4057007CDBBB /* 괄호 변환.swift */; };
Expand Down Expand Up @@ -50,7 +52,9 @@
334149992897EA4D008BB719 /* otherSolve.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = otherSolve.swift; sourceTree = "<group>"; };
334E6FEA28DE126E00865FDD /* 양과 늑대.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "양과 늑대.swift"; sourceTree = "<group>"; };
334E6FEC28DE326200865FDD /* 파괴되지 않은 건물.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "파괴되지 않은 건물.swift"; sourceTree = "<group>"; };
334E6FEE28DE344700865FDD /* 신고 결과 받기.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "신고 결과 받기.swift"; sourceTree = "<group>"; };
33A5DAF728D9C3AB00E4EB37 /* 큰 수 만들기.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "큰 수 만들기.swift"; sourceTree = "<group>"; };
33AE9BCA28F58A470081D069 /* 실패율.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "실패율.swift"; sourceTree = "<group>"; };
33B39B2A289C4C2D0065B484 /* 타겟 넘버.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "타겟 넘버.swift"; sourceTree = "<group>"; };
33CB361C28DDEF56009BEB59 /* 메뉴 리뉴얼.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "메뉴 리뉴얼.swift"; sourceTree = "<group>"; };
33CEFA5A28DA4057007CDBBB /* 괄호 변환.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "괄호 변환.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -129,6 +133,8 @@
33DFAE3F289814930075DD46 /* 가운데 글자 가져오기.swift */,
334149962897E910008BB719 /* 7-NoneNumberPlus */,
330407DE28C60ABB0052EA19 /* 성격 유형 검사하기.swift */,
334E6FEE28DE344700865FDD /* 신고 결과 받기.swift */,
33AE9BCA28F58A470081D069 /* 실패율.swift */,
);
path = level1;
sourceTree = "<group>";
Expand Down Expand Up @@ -212,11 +218,13 @@
334E6FEB28DE126E00865FDD /* 양과 늑대.swift in Sources */,
33DFAE42289823800075DD46 /* 서울에서 김서방 찾기.swift in Sources */,
33DFAE3C2898036B0075DD46 /* 신규 아이디 추천.swift in Sources */,
33AE9BCB28F58A470081D069 /* 실패율.swift in Sources */,
330407DF28C60ABB0052EA19 /* 성격 유형 검사하기.swift in Sources */,
33DFAE3E28980C360075DD46 /* 키패드 누르기.swift in Sources */,
33A5DAF828D9C3AB00E4EB37 /* 큰 수 만들기.swift in Sources */,
3316175728DCA81D001DAACE /* 양궁대회.swift in Sources */,
334149902897E853008BB719 /* main.swift in Sources */,
334E6FEF28DE344700865FDD /* 신고 결과 받기.swift in Sources */,
33DFAE40289814930075DD46 /* 가운데 글자 가져오기.swift in Sources */,
33B39B2B289C4C2D0065B484 /* 타겟 넘버.swift in Sources */,
3316175A28DDDCB7001DAACE /* 순위 검색.swift in Sources */,
Expand Down
Binary file not shown.
8 changes: 8 additions & 0 deletions Programmers/Programmers/level1/신고 결과 받기.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//
// 신고 결과 받기.swift
// Programmers1
//
// Created by hwangJi on 2022/09/24.
//

import Foundation
33 changes: 33 additions & 0 deletions Programmers/Programmers/level1/실패율.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// 실패율.swift
// Programmers1
//
// Created by hwangJi on 2022/10/11.
//

import Foundation

func solution(_ N:Int, _ stages:[Int]) -> [Int] {
var stageDict: [Int: Int] = [:]

for i in 1...N {
stageDict[i] = 0
}

for i in stages {
stageDict[i] = stageDict[i] != nil ? stageDict[i]! + 1 : 1
}

var stageCount = stages.count
var failureDict: [Int: Double] = [:]

for i in stageDict.keys.filter({ $0 <= N }).sorted() {
failureDict[i] = Double(stageDict[i]!)/Double(stageCount)
stageCount -= stageDict[i]!
}

var sortedDict = failureDict.sorted { $0.key < $1.key }
sortedDict = sortedDict.sorted { $0.value > $1.value }

return sortedDict.map { $0.key }
}

0 comments on commit d394305

Please sign in to comment.