-
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 #63 from AlgorithmWithMe/jimin/13week
[이지민] 기적의 매매법, 수 이어 쓰기 1, 등수 구하기, DNA
- Loading branch information
Showing
4 changed files
with
158 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,36 @@ | ||
package jimin.`13week` | ||
|
||
import java.io.BufferedReader | ||
import java.io.InputStreamReader | ||
|
||
/* | ||
<문제> | ||
[DNA](https://www.acmicpc.net/problem/1969) | ||
<구현 방법> | ||
알파벳 26개를 담는 리스트를 만들어 각 자리수 알파벳이 몇개인지 담았다. | ||
알파벳 최대인 것을 구하고 최대수를 n에서 뺀 값이 Hamming Distance이다. | ||
<트러블 슈팅> | ||
*/ | ||
|
||
fun main(): Unit = with(BufferedReader(InputStreamReader(System.`in`))) { | ||
val (n, m) = readLine().split(" ").map { it.toInt() } | ||
val DNAList = mutableListOf<String>() | ||
val alphabetList = MutableList(m) { MutableList(26) { 0 } } | ||
var DNA = "" | ||
var num = 0 | ||
repeat(n) { | ||
DNAList.add(readLine()) | ||
repeat(m) { idx -> | ||
alphabetList[idx][DNAList.last()[idx] - 'A'] += 1 | ||
} | ||
} | ||
repeat(m) { idx -> | ||
DNA += (alphabetList[idx].indexOf(alphabetList[idx].maxOf { it }) + 'A'.code).toChar() | ||
num += n - alphabetList[idx].maxOf { it } | ||
} | ||
println(DNA) | ||
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,56 @@ | ||
package jimin.`13week` | ||
|
||
import java.io.BufferedReader | ||
import java.io.InputStreamReader | ||
|
||
/* | ||
<문제> | ||
[기적의 매매법](https://www.acmicpc.net/problem/20546) | ||
<구현 방법> | ||
준현이는 가능한 첫번째꺼를 기준으로 계산하고, | ||
성민이는 up과 down을 계산하여 자산을 계산한다. | ||
<트러블 슈팅> | ||
money가 주식 어느 하나보다 크지 않을 때 first함수를 사용하면 runTime 에러가 난다. | ||
*/ | ||
|
||
fun main(): Unit = with(BufferedReader(InputStreamReader(System.`in`))) { | ||
val money = readLine().toInt() | ||
val stockPrices = readLine().split(" ").map { it.toInt() } | ||
val junStock = if (stockPrices.minOf { it } < money) stockPrices.first{ it <= money } else 0 | ||
val junPrice = if (junStock == 0) money else (money / junStock) * stockPrices.last() + money % junStock | ||
var up = 0 | ||
var down = 0 | ||
var stockNum = 0 | ||
var cash = money | ||
stockPrices.forEachIndexed { idx, price -> | ||
if (idx != 0 && stockPrices[idx - 1] < price) { | ||
up += 1 | ||
down = 0 | ||
} else if (idx != 0 && stockPrices[idx - 1] > price) { | ||
down += 1 | ||
up = 0 | ||
} else { | ||
down = 0 | ||
up = 0 | ||
} | ||
if (up == 3) { | ||
cash += price * stockNum | ||
stockNum = 0 | ||
} | ||
if (down >= 3) { | ||
val num = cash / price | ||
cash -= price * num | ||
stockNum += num | ||
} | ||
} | ||
val sungPrice = stockNum * stockPrices.last() + cash | ||
if (junPrice > sungPrice) { | ||
println("BNP") | ||
} else if (junPrice < sungPrice) { | ||
println("TIMING") | ||
} else { | ||
println("SAMESAME") | ||
} | ||
} |
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 jimin.`13week` | ||
|
||
import java.io.BufferedReader | ||
import java.io.InputStreamReader | ||
|
||
/* | ||
<문제> | ||
[등수 구하기](https://www.acmicpc.net/problem/1205) | ||
<구현 방법> | ||
n이 0 이면 무조건 1 출력, | ||
n과 p가 같으면 점수 꼴지가 s와 같거나 작다면 -1 출력, | ||
아니면 scoreList에 add해서 내림차순정렬해서 index구하기 | ||
<트러블 슈팅> | ||
*/ | ||
|
||
fun main(): Unit = with(BufferedReader(InputStreamReader(System.`in`))) { | ||
val (n, s, p) = readLine().split(" ").map { it.toInt() } | ||
if (n == 0) { | ||
println(1) | ||
return@with | ||
} | ||
val scoreList = readLine().split(" ").map { it.toInt() }.toMutableList() | ||
if (n == p) { | ||
if (scoreList.last() >= s) { | ||
println(-1) | ||
return@with | ||
} | ||
} | ||
scoreList.add(s) | ||
scoreList.sortDescending() | ||
println(scoreList.indexOf(s) + 1) | ||
} |
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,32 @@ | ||
package jimin.`13week` | ||
|
||
import java.io.BufferedReader | ||
import java.io.InputStreamReader | ||
|
||
/* | ||
<문제> | ||
[수 이어 쓰기 1](https://www.acmicpc.net/problem/1748) | ||
<구현 방법> | ||
일의 자리 숫자일 때는 n이나 9를 넣는다. | ||
일의 자리 이상일 때는 99, 999, 9999 일때의 경우를 더해주면서 | ||
마지막 q-1일때도 계산해 더해준다. | ||
<트러블 슈팅> | ||
*/ | ||
|
||
fun main(): Unit = with(BufferedReader(InputStreamReader(System.`in`))) { | ||
val n = readLine().toInt() | ||
val q = n.toString().length - 1 | ||
var sum = if (n < 10) n else 9 | ||
var ten = 1 | ||
repeat(q) { | ||
ten *= 10 | ||
if (it == q - 1) { | ||
sum += (n - (ten - 1)) * (it + 2) | ||
} else { | ||
sum += (ten * 9) * (it + 2) | ||
} | ||
} | ||
println(sum) | ||
} |