diff --git "a/src/main/kotlin/heejik/5week/\352\260\200\353\241\234\354\210\230.kt" "b/src/main/kotlin/heejik/5week/\352\260\200\353\241\234\354\210\230.kt" new file mode 100644 index 00000000..7d74ab17 --- /dev/null +++ "b/src/main/kotlin/heejik/5week/\352\260\200\353\241\234\354\210\230.kt" @@ -0,0 +1,36 @@ +package heejik.`5week` + +fun main() { + + val n = readln().toInt() + val tree = mutableListOf() + val diff = mutableListOf() + var gcd = 1 + + repeat(n) { + val location = readln().toInt() + if (tree.isNotEmpty()) { + diff.add(location - tree.last()) + } + tree.add(location) + } + + gcd = getGcd(diff[0], diff[1]) + for (i in 2 until diff.size) { + gcd = getGcd(gcd,diff[i]) + } + + println(((tree.last() - tree.first()) / gcd) + 1 - tree.size) + +} + +fun getGcd(_a: Int, _b: Int): Int { + var a = _a + var b = _b + while (b > 0) { + val tmp = a + a = b + b = tmp % b + } + return a +} \ No newline at end of file diff --git "a/src/main/kotlin/heejik/5week/\353\236\234\354\204\240 \354\236\220\353\245\264\352\270\260.kt" "b/src/main/kotlin/heejik/5week/\353\236\234\354\204\240 \354\236\220\353\245\264\352\270\260.kt" new file mode 100644 index 00000000..c180ee78 --- /dev/null +++ "b/src/main/kotlin/heejik/5week/\353\236\234\354\204\240 \354\236\220\353\245\264\352\270\260.kt" @@ -0,0 +1,46 @@ +package heejik.`5week` + +import java.io.BufferedReader +import java.io.InputStreamReader +import kotlin.system.exitProcess + +val lines = mutableListOf() + +fun main(): Unit = with(BufferedReader(InputStreamReader(System.`in`))) { + var answer = 0L + val (k, n) = readLine().split(' ').map { it.toInt() } + var s = 0L + + repeat(k) { + val line = readLine().toLong() + lines.add(line) + s += line + } + + var start = 0L + var end = s / n + if (end == 1L) { + println(1) + exitProcess(0) + } + while (start <= end) { + val mid = (end + start) / 2 + val cnt = isCorrect(mid) + if (cnt >= n) { + answer = mid + start = mid + 1 + } else { + end = mid - 1 + } + } + + println(answer) +} + +fun isCorrect(length: Long): Long { + var cnt = 0L + lines.forEach { + cnt += it / length + } + return cnt +} \ No newline at end of file diff --git "a/src/main/kotlin/heejik/5week/\353\260\224\353\213\245 \354\236\245\354\213\235.kt" "b/src/main/kotlin/heejik/5week/\353\260\224\353\213\245 \354\236\245\354\213\235.kt" new file mode 100644 index 00000000..f2f29182 --- /dev/null +++ "b/src/main/kotlin/heejik/5week/\353\260\224\353\213\245 \354\236\245\354\213\235.kt" @@ -0,0 +1,26 @@ +package heejik.`5week` + +fun main() { + var answer = 0 + + val (n, m) = readln().split(' ').map { it.toInt() } + + val floor = arrayListOf().apply { + repeat(n) { + add(readln()) + } + } + + repeat(n) { i -> + answer += floor[i].split('|').filter { it.isNotEmpty() }.size + } + repeat(m) { j -> + var tmp = "" + repeat(n) { i -> + tmp += floor[i][j] + } + answer += tmp.split('-').filter { it.isNotEmpty() }.size + } + + println(answer) +} \ No newline at end of file diff --git "a/src/main/kotlin/heejik/5week/\353\271\231\352\263\240.kt" "b/src/main/kotlin/heejik/5week/\353\271\231\352\263\240.kt" new file mode 100644 index 00000000..258e6fe1 --- /dev/null +++ "b/src/main/kotlin/heejik/5week/\353\271\231\352\263\240.kt" @@ -0,0 +1,67 @@ +package heejik.`5week` + +import kotlin.system.exitProcess + +val bingo = arrayListOf>() + +fun main() { + var cnt = 0 + var bingoCnt = 0 + val chairMan = arrayListOf>() + + repeat(5) { + bingo.add(readln().split(' ').map { it.toInt() }.toMutableList()) + } + repeat(5) { + chairMan.add(readln().split(' ').map { it.toInt() }.toMutableList()) + } + + chairMan.forEachIndexed { _, ints -> + ints.forEachIndexed { _, num -> + bingo.forEachIndexed { _, row -> + if (num in row) { + cnt += 1 + row[row.indexOf(num)] = -1 + if (isBingo() >= 3) { + println(cnt) + exitProcess(0) + } + bingoCnt = 0 + } + } + } + } +} + +fun isBingo(): Int { + var cnt = 0 + var tmp = 0 + repeat(5) { i -> + if (bingo[i].filter { it == -1 }.size == 5) cnt += 1 + } + + repeat(5) { j -> + tmp = 0 + repeat(5) { i -> + if (bingo[i][j] == -1) { + tmp += 1 + } + if (tmp == 5) cnt += 1 + } + } + + tmp = 0 + repeat(5) { i -> + if (bingo[i][i] == -1) tmp += 1 + } + if (tmp == 5) cnt += 1 + + tmp = 0 + repeat(5) { i -> + if (bingo[i][4 - i] == -1) tmp += 1 + } + if (tmp == 5) cnt += 1 + + return cnt +} + diff --git "a/src/main/kotlin/heejik/5week/\355\202\271.kt" "b/src/main/kotlin/heejik/5week/\355\202\271.kt" new file mode 100644 index 00000000..c9b7e26c --- /dev/null +++ "b/src/main/kotlin/heejik/5week/\355\202\271.kt" @@ -0,0 +1,44 @@ +package heejik.`5week` + + +val y = listOf('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H') +val move = listOf("R", "L", "B", "T", "RT", "LT", "RB", "LB") +val dx = listOf(0, 0, -1, 1, 1, 1, -1, -1) +val dy = listOf(1, -1, 0, 0, 1, -1, 1, -1) + +fun main() { + + var (king, rock, n) = readln().split(' ') + + repeat(n.toInt()) { + val location = move.indexOf(readln()) + + var kingX = (king[1].digitToInt()) - 1 + var kingY = y.indexOf(king[0]) + + var rockX = (rock[1].digitToInt()) - 1 + var rockY = y.indexOf(rock[0]) + + val kingNx = kingX + dx[location] + val kingNy = kingY + dy[location] + + + if ((kingNx in 0..7 && kingNy in 0..7).not()) return@repeat + + if (kingNx == rockX && kingNy == rockY) { + val rockNx = rockX + dx[location] + val rockNy = rockY + dy[location] + if ((rockNx in 0..7 && rockNy in 0..7).not()) return@repeat + rockX = rockNx + rockY = rockNy + } + kingX = kingNx + kingY = kingNy + + king = (y[kingY].toString()) + (kingX + 1).toString() + rock = (y[rockY].toString()) + (rockX + 1).toString() + + } + println(king) + println(rock) +} \ No newline at end of file