diff --git a/storage/zeta/kt/completed/14229.kt b/storage/zeta/kt/completed/14229.kt new file mode 100644 index 0000000..b39b9ad --- /dev/null +++ b/storage/zeta/kt/completed/14229.kt @@ -0,0 +1,90 @@ +import kotlin.math.pow + +// A C G T + +class DNAIncludeManager { + val dnaRegistry = BooleanArray(5460) { false } + + fun updateRegistry(dna: String) { + val n = dna.length + for (i in 0 until n) { + for (len in 1..6) { + if (i + len > n) { + break; + } + dnaRegistry[encodeDNA(dna.subSequence(i, i + len))] = true + } + } + } + + fun getShortest(): String { + dnaRegistry.withIndex().forEach { (i, c) -> + if (!c) { + return decodeDNA(i).joinToString("") + } + } + return "" + } + + companion object { + fun convertDNAChar(c: Char): Int { + return when (c) { + 'A' -> 0 + 'C' -> 1 + 'G' -> 2 + 'T' -> 3 + else -> 0 + } + + } + + fun decodeDNAChar(x: Int): Char { + return when (x) { + 0 -> 'A' + 1 -> 'C' + 2 -> 'G' + 3 -> 'T' + else -> 'X' + } + } + + fun encodeDNA(seq: CharSequence): Int { + val n = seq.length + + return (4.0.pow(n) - 4).toInt() / 3 + seq.withIndex().sumOf { (i, c) -> + 4.0.pow(i.toDouble()).toInt() * convertDNAChar(c) + } + } + + fun decodeDNA(x: Int): List { + var target = x + + for (i in 1..6) { + val cx = 4.0.pow(i).toInt() + if (target < cx) { + val res = MutableList(i) { 'A' } + if (i != 1) { + target -= (4.0.pow(i) - 4).toInt() / 3 + } + + for (j in (0 until i).reversed()) { + val ct = 4.0.pow(j).toInt() + res[j] = decodeDNAChar(target / ct) + target %= ct + } + + return res + } + } + return listOf() + } + } +} + +fun main() = with(System.`in`.bufferedReader()) { + val manager = DNAIncludeManager() + val s = this.readLine().trimEnd() + + manager.updateRegistry(s) + println(manager.getShortest()) +} \ No newline at end of file diff --git a/storage/zeta/kt/completed/34052.kt b/storage/zeta/kt/completed/34052.kt new file mode 100644 index 0000000..8ca4312 --- /dev/null +++ b/storage/zeta/kt/completed/34052.kt @@ -0,0 +1,12 @@ +import java.io.StreamTokenizer + +fun main() = with(StreamTokenizer(System.`in`.bufferedReader())) { + if ((1..4).sumOf { + nextToken() + nval.toInt() + } <= 1500) { + println("Yes") + } else { + println("No") + } +} \ No newline at end of file