-
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.
Merge pull request #45 from AlgorithmWithMe/heejik/9week
[장희직] Java vs C++, 1,2,3 더하기 4, 도어맨, 배열 복원하기, 후위 표기식2
- Loading branch information
Showing
5 changed files
with
208 additions
and
0 deletions.
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,26 @@ | ||
package heejik.`9week` | ||
|
||
// 답보풀: https://ku-hug.tistory.com/m/209 | ||
|
||
class `1, 2, 3 더하기 4` { | ||
|
||
fun solve() { | ||
|
||
val cnt = MutableList(10001) { 1 } | ||
|
||
for (i in 2..10000) { | ||
cnt[i] += cnt[i-2] | ||
} | ||
|
||
for (i in 3..10000) { | ||
cnt[i] += cnt[i-3] | ||
} | ||
repeat(readln().toInt()) { | ||
println(cnt[readln().toInt()]) | ||
} | ||
} | ||
} | ||
|
||
fun main() { | ||
`1, 2, 3 더하기 4`().solve() | ||
} |
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,56 @@ | ||
package heejik.`9week` | ||
|
||
class `Java vs C++` { | ||
|
||
data class JAVA(val variable: String) { | ||
var cpp = "" | ||
fun toCPP(): String { | ||
variable.forEach { c -> | ||
if (c.isUpperCase()) { | ||
cpp += '_' | ||
cpp += c.lowercaseChar() | ||
} else { | ||
cpp += c | ||
} | ||
} | ||
return cpp | ||
} | ||
} | ||
|
||
data class CPP(val variable: String) { | ||
var java = "" | ||
fun toJava(): String { | ||
var isUpper = false | ||
variable.forEach { c -> | ||
if (c == '_') { | ||
isUpper = true | ||
} else if (isUpper) { | ||
java += c.uppercaseChar() | ||
isUpper = false | ||
} else { | ||
java += c | ||
} | ||
} | ||
return java | ||
} | ||
} | ||
|
||
fun solve() { | ||
readln().run { | ||
if (this.first().isLetter().not() || this.first().isLowerCase().not() || this.last() == '_' || this.contains("__")) { | ||
println("Error!") | ||
} else if (this.contains('_') && this.none { it.isUpperCase() }) { // CPP asd_asd | ||
println(CPP(this).toJava()) | ||
} else if (this.contains('_').not()){ // JAVA | ||
println(JAVA(this).toCPP()) | ||
} else { | ||
println("Error!") | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
fun main() { | ||
`Java vs C++`().solve() | ||
} |
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,49 @@ | ||
package heejik.`9week` | ||
|
||
class 도어맨 { | ||
|
||
|
||
fun solve() { | ||
|
||
val x = readln().toInt() | ||
var answer = 0 | ||
val order = readln() | ||
var wCount = 0 | ||
var mCount = 0 | ||
var isChanged = false | ||
|
||
kotlin.run { | ||
order.forEachIndexed { index, _c -> | ||
var c = _c | ||
if (isChanged) { | ||
isChanged = false | ||
c = c.change() | ||
} | ||
if (c == 'W') { | ||
if (wCount - mCount == x) { | ||
if (index == order.length - 1 || order[index + 1] == 'W') return@run | ||
isChanged = true | ||
mCount++ | ||
} else wCount++ | ||
} else { | ||
if (mCount - wCount == x) { | ||
if (index == order.length - 1 || order[index + 1] == 'M') return@run | ||
isChanged = true | ||
wCount++ | ||
} else mCount++ | ||
} | ||
answer++ | ||
} | ||
} | ||
println(answer) | ||
} | ||
|
||
private fun Char.change() = if (this == 'W') 'M' else 'W' | ||
|
||
} | ||
|
||
fun main() { | ||
|
||
도어맨().solve() | ||
|
||
} |
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,38 @@ | ||
package heejik.`9week` | ||
|
||
class `배열 복원하기` { | ||
|
||
fun solve() { | ||
|
||
val (h, w, x, y) = readln().split(' ').map { it.toInt() } | ||
|
||
val a = MutableList(h) { MutableList(w) { 0 } } | ||
val b = mutableListOf<MutableList<Int>>() | ||
|
||
repeat(h + x) { | ||
b.add(readln().split(' ').map { it.toInt() }.toMutableList()) | ||
} | ||
|
||
for (i in 0 until h) { | ||
for (j in 0 until w) { | ||
if (i >= x && j >= y) { | ||
a[i][j] = b[i][j] - a[i-x][j-y] | ||
} | ||
else { | ||
a[i][j] = b[i][j] | ||
} | ||
} | ||
} | ||
a.forEach { row -> | ||
row.forEach { value -> | ||
print("$value ") | ||
} | ||
println() | ||
} | ||
} | ||
} | ||
|
||
|
||
fun main() { | ||
`배열 복원하기`().solve() | ||
} |
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,39 @@ | ||
package heejik.`9week` | ||
|
||
class `후위 표기식2` { | ||
|
||
val operands = mutableListOf<Double>() | ||
|
||
fun solve() { | ||
val n = readln().toInt() | ||
var postfix = readln().chunked(1).toMutableList() | ||
|
||
repeat(n) { cnt -> | ||
val num = readln() | ||
postfix = postfix.map { | ||
if (it.contains('A' + cnt)) num | ||
else it | ||
}.toMutableList() | ||
} | ||
|
||
postfix.forEach { | ||
if (it.toIntOrNull() != null) { | ||
operands.add(it.toDouble()) | ||
} else { | ||
val a = operands.removeLast() | ||
val b = operands.removeLast() | ||
when (it.first()) { | ||
'*' -> operands.add(b * a) | ||
'+' -> operands.add(b + a) | ||
'/' -> operands.add(b / a) | ||
'-' -> operands.add(b - a) | ||
} | ||
} | ||
} | ||
println(String.format("%.2f", operands.first())) | ||
} | ||
} | ||
|
||
fun main() { | ||
`후위 표기식2`().solve() | ||
} |