Open Source Your Knowledge, Become a Contributor
Technology knowledge has to be shared and made accessible for free. Join the movement.
Kotlin
Checking the sample code
My solution is basicly Java. A more idiomatic Kotlin-like solution is needed here to show...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import java.util.*
fun main(args : Array<String>) {
val input = Scanner(System.`in`)
val m: String = input.nextLine()
val c = arrayOf("00", "0")
val b = StringBuilder()
for (w in m)
b.append(String.format("%1$" + 7 + "s", Integer.toBinaryString(w.toByte().toInt())).replace(' ', '0'))
val a = StringBuilder()
a.append(c[b.get(0) - '0'] + " 0")
for (i in 1 until b.length)
if (b.get(i) == b.get(i - 1))
a.append("0")
else
a.append(" " + c[b.get(i) - '0'] + " 0")
println(a.toString())
// To debug: System.err.println("Debug messages...");
}
Enter to Rename, Shift+Enter to Preview
Looking at the syntax
- TODO
Other characteristics
- TODO
Resources to check
Coming next...
Open Source Your Knowledge: become a Contributor and help others learn. Create New Content