-
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 #34 from kogorithm/week7_jaewon
[Week7] 김재원 : 프린터 큐, 요세푸스 문제, 크리스마스 선물, 스택 수열, 쇠막대기
- Loading branch information
Showing
5 changed files
with
138 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,23 @@ | ||
package `7week`.jaewon | ||
|
||
fun main(){ | ||
val list = readln() | ||
var stick = 0 | ||
var answer = 0 | ||
var i = 0 | ||
while (i < list.length){ | ||
when(list[i]){ | ||
'(' -> { | ||
if(list[i+1] == ')'){ | ||
answer += stick | ||
i++ | ||
}else stick++ | ||
}else -> { | ||
answer++ | ||
stick-- | ||
} | ||
} | ||
i++ | ||
} | ||
println(answer) | ||
} |
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,34 @@ | ||
package `7week`.jaewon | ||
|
||
import java.util.Stack | ||
|
||
/** | ||
* 1부터 n까지 반복하면서 스택에 넣고, | ||
* 맨 위의 값이 만들어야 하는 값과 같다면 빼고, 아니면 다음 걸 넣어준다. | ||
*/ | ||
|
||
fun main(){ | ||
val n = readln().toInt() | ||
val willMake = arrayListOf<Int>() | ||
val stack = Stack<Int>() | ||
val answer = arrayListOf<String>() | ||
repeat(n){ willMake.add(readln().toInt()) } | ||
|
||
var cnt = 1 | ||
while (willMake.isNotEmpty()){ | ||
if (cnt > n+1){ | ||
println("NO") | ||
return | ||
} | ||
if(stack.isNotEmpty() && stack.peek() == willMake[0]){ | ||
answer.add("-") | ||
stack.pop() | ||
willMake.removeFirst() | ||
}else{ | ||
answer.add("+") | ||
stack.push(cnt) | ||
cnt++ | ||
} | ||
} | ||
println(answer.joinToString("\n")) | ||
} |
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,22 @@ | ||
package `7week`.jaewon | ||
|
||
fun main(){ | ||
val (n,k) = readln().split(" ").map { it.toInt()} | ||
val yo = arrayListOf<Int>() | ||
val answer : ArrayList<Int> = arrayListOf() | ||
repeat(n){ yo.add(it+1)} | ||
|
||
var count = 1 | ||
while (yo.isNotEmpty()){ | ||
if(count == k){ | ||
answer.add(yo[0]) | ||
count = 1 | ||
}else{ | ||
yo.add(yo[0]) | ||
count++ | ||
} | ||
yo.removeFirst() | ||
} | ||
|
||
println(answer.joinToString(", ","<",">")) | ||
} |
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 `7week`.jaewon | ||
|
||
import java.io.BufferedReader | ||
import java.io.InputStreamReader | ||
import java.util.* | ||
|
||
fun main(){ | ||
val br = BufferedReader(InputStreamReader(System.`in`)) | ||
val m = br.readLine().toInt() | ||
val gift = PriorityQueue(Collections.reverseOrder<Int>()) | ||
repeat(m){ | ||
val st = StringTokenizer(br.readLine()) | ||
val n = st.nextToken().toInt() | ||
if(n == 0){ | ||
if(gift.isNotEmpty()){ | ||
println(gift.poll()) | ||
}else{ | ||
println(-1) | ||
} | ||
}else{ | ||
repeat(n){ | ||
gift.add(st.nextToken().toInt()) | ||
} | ||
} | ||
} | ||
} |
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,33 @@ | ||
package `7week`.jaewon | ||
|
||
/** | ||
* while문으로 반복 | ||
* 현재 중요도가 제일 높은지 확인 | ||
* 높다면 -> 제거, count ++ - ( count default = 1 ) | ||
* m과 같다면 print하고 종료. | ||
* 아니라면 맨 뒤로 보내기 | ||
*/ | ||
|
||
fun main(){ | ||
repeat(readln().toInt()){ | ||
val (_,m) = readln().split(" ").map{it.toInt()} | ||
val temp = readln().split(" ").map { it.toInt()} | ||
val paper = mutableListOf<Pair<Int,Int>>() | ||
temp.forEachIndexed { index, i -> paper.add(Pair(i,index)) } | ||
|
||
var count = 1 | ||
while(true){ | ||
val top = paper.maxOf{ it.first } | ||
if(paper[0].first == top){ | ||
if(paper[0].second == m){ | ||
println(count) | ||
break | ||
} | ||
count++ | ||
}else{ | ||
paper.add(paper[0]) | ||
} | ||
paper.removeAt(0) | ||
} | ||
} | ||
} |