-
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 #275 from wellFoundedDevelopers/byeonghee/65week
[소병희] - 사과나무, 후위 표기식
- Loading branch information
Showing
2 changed files
with
75 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,29 @@ | ||
package byeonghee.week65 | ||
|
||
class 소병희_사과나무 { | ||
companion object { | ||
fun solve() = with(System.`in`.bufferedReader()) { | ||
val n = readLine().toInt() | ||
val trees = IntArray(n) | ||
|
||
var oneCnt = 0 //1 짜리 물뿌리개의 최소 필요개수 | ||
var twoCnt = 0 // 2짜리 물뿌리개의 최대 필요개수 | ||
var sum = 0 | ||
|
||
readLine().split(" ").forEachIndexed { i, v -> | ||
trees[i] = v.toInt().also { | ||
if (it % 2 == 1) oneCnt++ | ||
if (it >= 2) twoCnt += it / 2 | ||
sum += it | ||
} | ||
} | ||
|
||
if (sum % 3 > 0 || oneCnt > twoCnt) println("NO") | ||
else println("YES") | ||
} | ||
} | ||
} | ||
|
||
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,46 @@ | ||
package byeonghee.week65 | ||
|
||
class 소병희_후위표기식 { | ||
companion object { | ||
val op = charArrayOf('+', '-', '*', '/', '(', ')') | ||
|
||
fun solve() = with(System.`in`.bufferedReader()) { | ||
val st = ArrayDeque<Char>() | ||
val sb = StringBuilder() | ||
val pri = HashMap<Char, Int>() | ||
pri.put('+', 1) | ||
pri.put('-', 1) | ||
pri.put('*', 2) | ||
pri.put('/', 2) | ||
pri.put('(', 0) | ||
pri.put(')', 0) | ||
|
||
readLine().forEach { i -> | ||
if (i !in op) sb.append(i) | ||
else if (i == '(') st.add(i) | ||
else if (i == ')') { | ||
while (st.isNotEmpty() && st.last() != '(') { | ||
sb.append(st.removeLast()) | ||
} | ||
if (st.isNotEmpty()) st.removeLast() | ||
} | ||
else { | ||
while(st.isNotEmpty() && pri[st.last()]!! >= pri[i]!!) { | ||
sb.append(st.removeLast()) | ||
} | ||
st.add(i) | ||
} | ||
} | ||
|
||
while(st.isNotEmpty()) { | ||
sb.append(st.removeLast()) | ||
} | ||
|
||
println(sb) | ||
} | ||
} | ||
} | ||
|
||
fun main() { | ||
소병희_후위표기식.solve() | ||
} |