-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Week6] 전현수: 거리두기 확인, 동전 0, 수리공 항승, 큰 수 만들기, 신입 사원, 잃어버린 괄호 (#27)
* Feat: 동전 0 추가 * Feat: 수리공 항승 추가 * Feat: 큰 수 만들기 추가 * Feat: 신입 사원 추가 * Feat: 잃어버린 괄호 추가 * Feat: 거리두기 확인 추가 * Feat: 캠핑 추가
- Loading branch information
Showing
8 changed files
with
341 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package `5week`.hyunsoo | ||
|
||
import java.util.* | ||
|
||
class `거리두기 확인` { | ||
companion object { | ||
fun getSolution(): Solution { | ||
return Solution() | ||
} | ||
} | ||
|
||
class Solution { | ||
|
||
fun solution(places: Array<Array<String>>): IntArray { | ||
|
||
var answer = intArrayOf() | ||
|
||
places.forEach { curRoom -> | ||
|
||
// 거리두기 규칙을 지켰는지 여부 | ||
var followed = true | ||
|
||
for (x in 0 until 5){ | ||
for (y in 0 until 5){ | ||
if (!check(x,y,curRoom)) { | ||
followed = false | ||
} | ||
} | ||
} | ||
// 규칙을 따랐다면 | ||
if (followed) answer += 1 | ||
// 규칙을 따르지 않았다면 | ||
else answer += 0 | ||
|
||
} | ||
|
||
return answer | ||
} | ||
|
||
fun check(x: Int, y: Int, room: Array<String>): Boolean{ | ||
|
||
val curCell = room[x][y] | ||
// 응시자가 있는 자리가 아니라면 탐색을 하지 않음 | ||
if (curCell != 'P') return true | ||
|
||
// 상하좌우 탐색 | ||
val dx = intArrayOf(-1,1,0,0) | ||
val dy = intArrayOf(0,0,-1,1) | ||
|
||
for (no in 0 until 4){ | ||
if (x + dx[no] < 0 || x + dx[no] >= 5 || y + dy[no] < 0 || y + dy[no] >= 5) continue | ||
if (room[x+dx[no]][y+dy[no]] == 'P') | ||
return false | ||
} | ||
|
||
// 건너건너도 탐색 | ||
val dx2 = intArrayOf(-2,2,0,0) | ||
val dy2 = intArrayOf(0,0,-2,2) | ||
|
||
for (no in 0 until 4){ | ||
if (x + dx2[no] < 0 || x + dx2[no] >= 5 || y + dy2[no] < 0 || y + dy2[no] >= 5) continue | ||
// 건너건너에 사람이 존재하면서, 그 사이에 테이블도 아닌경우 | ||
if(room[x+dx2[no]][y+dy2[no]] == 'P' && room[x+dx[no]][y+dy[no]] != 'X') | ||
return false | ||
} | ||
|
||
// 대각선 탐색(좌상, 우상, 우하, 좌하 순) | ||
val dx3 = intArrayOf(-1,-1,1,1) | ||
val dy3 = intArrayOf(-1,1,1,-1) | ||
|
||
for (no in 0 until 4){ | ||
if (x + dx3[no] < 0 || x + dx3[no] >= 5 || y + dy3[no] < 0 || y + dy3[no] >= 5) continue | ||
// 대각선에 사람이 존재하면서 사이에 파티션으로 가려지지 않은 경우 | ||
if (room[x+dx3[no]][y+dy3[no]] == 'P' | ||
&& (room[x+dx3[no]][y] != 'X' || room[x][y+dy3[no]] != 'X')) return false | ||
} | ||
|
||
return true | ||
|
||
} | ||
|
||
} | ||
|
||
} | ||
|
||
val places: Array<Array<String>> = arrayOf( | ||
arrayOf("POOOP", "OXXOX", "OPXPX", "OOXOX", "POXXP"), | ||
arrayOf("POOPX", "OXPXP", "PXXXO", "OXXXO", "OOOPP"), | ||
arrayOf("PXOPX", "OXOXP", "OXPOX", "OXXOP", "PXPOX"), | ||
arrayOf("OOOXX", "XOOOX", "OOOXX", "OXOOX", "OOOOO"), | ||
arrayOf("PXPXP", "XPXPX", "PXPXP", "XPXPX", "PXPXP"), | ||
) | ||
|
||
fun main() { | ||
val solution = `거리두기 확인`.getSolution() | ||
solution.solution(places).forEach { | ||
println(it) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package `6week`.hyunsoo | ||
|
||
fun main() { | ||
|
||
var (n, k) = readln().split(" ").map { it.toInt() } | ||
|
||
val coinList = mutableListOf<Int>() | ||
var ans = 0 | ||
repeat(n) { | ||
coinList.add(readln().toInt()) | ||
} | ||
|
||
// 내림차순 정렬 | ||
coinList.sortedByDescending { it }.forEach { | ||
// 코인이 나누어 진다면 해당 코인만큼 계산해줌. | ||
val coinCnt = k / it | ||
if (coinCnt > 0) { | ||
ans += coinCnt | ||
k -= coinCnt * it | ||
} | ||
} | ||
println(ans) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package `6week`.hyunsoo | ||
|
||
fun main() { | ||
|
||
// 물이 새는 곳의 개수 n, 테이프의 길이 l | ||
val (n, l) = readln().split(" ").map { it.toInt() } | ||
|
||
// 누수된 곳 - 오름차순으로 정렬함. | ||
val whereLeaked = readln().split(" ").map { it.toInt() }.sorted() | ||
|
||
// 필요한 테이프의 개수 | ||
var needTape = 0 | ||
|
||
// 마지막으로 테이프를 붙인 위치 | ||
var lastLocation = 0f | ||
|
||
// 누수된 곳을 forEachIndexed를 사용하여 순차 탐색. | ||
whereLeaked.forEachIndexed { index, location -> | ||
|
||
// 첫 번째(index == 0 일 때)에는 무조건 테이프를 붙여야함. | ||
// 테이프 붙임 처리. | ||
if (index == 0) { | ||
// 마지막으로 테이프를 붙인 위치는 테이프를 붙인 위치 - 0.5를 해줌. | ||
lastLocation = location - 0.5f | ||
// 필요한 테이프 1 증가. | ||
needTape++ | ||
return@forEachIndexed | ||
} | ||
|
||
// 테이프 붙임처리 | ||
if ((lastLocation + l) < location) { | ||
// 마지막으로 테이프를 붙인 위치는 테이프를 붙인 위치 - 0.5를 해줌. | ||
lastLocation = location - 0.5f | ||
// 필요한 테이프 1 증가. | ||
needTape++ | ||
} | ||
|
||
} | ||
|
||
println(needTape) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package `6week`.hyunsoo | ||
|
||
fun main(){ | ||
|
||
// 테스트 케이스만큼 반복 | ||
val t = readln().toInt() | ||
repeat(t){ | ||
|
||
// 서류심사 순위, 면접 순위순으로 저장. | ||
val gradeList = mutableListOf<Pair<Int,Int>>() | ||
// 지원자의 수 | ||
val n = readln().toInt() | ||
// 뽑을 수 있는 최대 지원자의 수 | ||
var ans = 0 | ||
// 현재까지 뽑힌 지원자의 면접 순위중 가장 낮은 순위를 담을 변수 | ||
var maxRank = Int.MAX_VALUE | ||
|
||
// 지원자의 성적순위를 저장 | ||
repeat(n){ | ||
val rankData = readln().split(" ").map { it.toInt() } | ||
gradeList.add(Pair(rankData[0],rankData[1])) | ||
} | ||
|
||
// 지원자의 서류심사 순위로 오름차순 정렬 | ||
gradeList.sortBy{it.first} | ||
|
||
gradeList.forEachIndexed { index, curApplicant -> | ||
|
||
// 지원자들의 서류심사 순위로 이미 정렬이 되었기 때문에 | ||
// 현재 뽑힌 지원자들의 면접 순위의 가장 낮은 등수 보다 작다면 뽑힐 수 있다는 뜻 | ||
if (maxRank > curApplicant.second){ | ||
maxRank = curApplicant.second | ||
ans++ | ||
} | ||
|
||
} | ||
|
||
println(ans) | ||
gradeList.clear() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package `6week`.hyunsoo | ||
|
||
fun main(){ | ||
|
||
// 수식을 입력 받음. - 뒤의 수를 최대로 만들어라. | ||
val expression = readln() | ||
// '-' 의 위치 | ||
var minusLoation = -1 | ||
// 연산자들의 위치 | ||
val whereIsOperator = mutableListOf<Int>() | ||
// 계산이 되어질 수(정답 값) | ||
var num = 0 | ||
|
||
expression.forEachIndexed{index, it -> | ||
|
||
// '-' 의 위치 | ||
if (it == '-') { | ||
if (minusLoation == -1) minusLoation = index | ||
whereIsOperator.add(index) | ||
} | ||
// '+'의 위치 | ||
if (it == '+') { | ||
whereIsOperator.add(index) | ||
} | ||
|
||
} | ||
|
||
// 문자열 파싱된 마지막 인덱스 | ||
var lastIndex = 0 | ||
// 연산자를 분리한 순수 숫자 | ||
var dividedNum = 0 | ||
|
||
// 연산자와 숫자들을 분리하는 작업 | ||
whereIsOperator.forEach { indexForOperator -> | ||
|
||
dividedNum = expression.substring(lastIndex,indexForOperator).toInt() | ||
lastIndex = indexForOperator+1 | ||
|
||
// - 이후의 숫자들은 전부 -로 처리 | ||
if (indexForOperator <= minusLoation || minusLoation == -1){ | ||
num += dividedNum | ||
} else { | ||
num -= dividedNum | ||
} | ||
} | ||
|
||
// 마지막 연산자뒤에 숫자가 담겨야함. | ||
dividedNum = expression.substring(lastIndex,expression.length).toInt() | ||
if (minusLoation == -1){ | ||
num += dividedNum | ||
} else { | ||
num -= dividedNum | ||
} | ||
|
||
println(num) | ||
|
||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package `6week`.hyunsoo | ||
|
||
fun main() { | ||
|
||
var cnt = 1 | ||
|
||
while (true) { | ||
|
||
val (l, p, v) = readln().split(" ").map { it.toInt() } | ||
if (l == 0 && p == 0 && v == 0) break | ||
|
||
val useWhole = v / p * l | ||
var useSperate = v % p | ||
if (l < useSperate) useSperate = l | ||
|
||
println("Case ${cnt++}: ${useWhole + useSperate}") | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package `6week`.hyunsoo | ||
|
||
import java.util.Stack | ||
class `큰 수 만들기` { | ||
companion object { | ||
fun getSolution(): Solution { | ||
return Solution() | ||
} | ||
} | ||
|
||
class Solution { | ||
fun solution(number: String, k: Int): String { | ||
// 스택(LIFO) | ||
val stack = Stack<Int>() | ||
// 정답의 길이 = number의 길이 - 제거할 수의 개수 | ||
val stdLen = number.length - k | ||
// 정답이 담길 변수 | ||
var answer = "" | ||
// 지워진 개수 | ||
var removedCnt = 0 | ||
|
||
// 앞에 있을수록 수가 커야 더 큰 수 | ||
number.forEach{ | ||
|
||
val curNum = it - '0' | ||
|
||
// 현재 스택이 비어있지 않고, | ||
// 현재 탐색하는 수가 지금까지 뽑은 수보다 크고 | ||
// 아직 숫자를 제거할 기회가 남았다면 | ||
// stack에서 pop() | ||
while (stack.isNotEmpty() | ||
&& curNum > stack.peek() | ||
&& removedCnt < k){ | ||
stack.pop() | ||
removedCnt++ | ||
} | ||
stack.add(curNum) | ||
|
||
} | ||
|
||
// 길이가 stdLen보다 크다면 뒷부분 잘라주기 | ||
if(stack.size > stdLen){ | ||
answer = stack.subList(0, stdLen).joinToString("") | ||
} else answer = stack.joinToString("") | ||
|
||
return answer | ||
} | ||
|
||
} | ||
} | ||
|
||
fun main() { | ||
val solution = `큰 수 만들기`.getSolution() | ||
println(solution.solution("1924", 2)) | ||
println(solution.solution("1231234", 3)) | ||
println(solution.solution("4177252841", 4)) | ||
|
||
} |