Skip to content

Commit

Permalink
#9 - 크레인 인형뽑기 게임 문제 풀이
Browse files Browse the repository at this point in the history
  • Loading branch information
hwangJi-dev committed Aug 1, 2022
1 parent 7c80765 commit 3febd99
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ProgrammersLevel1/ProgrammersLevel1.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
33DFAE3E28980C360075DD46 /* 키패드 누르기.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33DFAE3D28980C360075DD46 /* 키패드 누르기.swift */; };
33DFAE40289814930075DD46 /* 가운데 글자 가져오기.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33DFAE3F289814930075DD46 /* 가운데 글자 가져오기.swift */; };
33DFAE42289823800075DD46 /* 서울에서 김서방 찾기.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33DFAE41289823800075DD46 /* 서울에서 김서방 찾기.swift */; };
33DFAE44289842B00075DD46 /* 크레인 인형뽑기 게임.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33DFAE43289842B00075DD46 /* 크레인 인형뽑기 게임.swift */; };
/* End PBXBuildFile section */

/* Begin PBXCopyFilesBuildPhase section */
Expand All @@ -37,6 +38,7 @@
33DFAE3D28980C360075DD46 /* 키패드 누르기.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "키패드 누르기.swift"; sourceTree = "<group>"; };
33DFAE3F289814930075DD46 /* 가운데 글자 가져오기.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "가운데 글자 가져오기.swift"; sourceTree = "<group>"; };
33DFAE41289823800075DD46 /* 서울에서 김서방 찾기.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "서울에서 김서방 찾기.swift"; sourceTree = "<group>"; };
33DFAE43289842B00075DD46 /* 크레인 인형뽑기 게임.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "크레인 인형뽑기 게임.swift"; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -75,6 +77,7 @@
33DFAE3D28980C360075DD46 /* 키패드 누르기.swift */,
33DFAE3F289814930075DD46 /* 가운데 글자 가져오기.swift */,
33DFAE41289823800075DD46 /* 서울에서 김서방 찾기.swift */,
33DFAE43289842B00075DD46 /* 크레인 인형뽑기 게임.swift */,
);
path = ProgrammersLevel1;
sourceTree = "<group>";
Expand Down Expand Up @@ -151,6 +154,7 @@
33DFAE3E28980C360075DD46 /* 키패드 누르기.swift in Sources */,
334149902897E853008BB719 /* main.swift in Sources */,
33DFAE40289814930075DD46 /* 가운데 글자 가져오기.swift in Sources */,
33DFAE44289842B00075DD46 /* 크레인 인형뽑기 게임.swift in Sources */,
3341499A2897EA4D008BB719 /* otherSolve.swift in Sources */,
334149982897E948008BB719 /* solve.swift in Sources */,
);
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// 크레인 인형뽑기 게임.swift
// ProgrammersLevel1
//
// Created by hwangJi on 2022/08/02.
//

import Foundation

func solution(_ board:[[Int]], _ moves:[Int]) -> Int {
var gameBoard: [[Int]] = board
var stack: [Int] = []
var count: Int = 0

for i in moves {
for j in 0..<gameBoard.count {
if gameBoard[j][i - 1] != 0 {
if stack.last == gameBoard[j][i - 1] {
stack.removeLast()
count += 1
} else {
stack.append(gameBoard[j][i - 1])
}
gameBoard[j][i - 1] = 0
break
}
}
}

return count * 2
}
Binary file not shown.

0 comments on commit 3febd99

Please sign in to comment.