Skip to content

Instantly share code, notes, and snippets.

@crakaC
Last active February 8, 2021 08:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crakaC/2bf7dce25b31009058d8129f7b95bd47 to your computer and use it in GitHub Desktop.
Save crakaC/2bf7dce25b31009058d8129f7b95bd47 to your computer and use it in GitHub Desktop.
競プロ用テンプレその2
import java.io.PrintWriter
import java.io.InputStream
fun main(){
flush()
}
fun println(any: Any?){stdout.println(any)}
fun flush(){stdout.flush()}
fun readLine() = stdin.readLine()
fun readInt() = stdin.readInt()
fun readInts(n: Int) = IntArray(n){stdin.readInt()}
fun readIndices(n: Int) = IntArray(n){readInt().dec()}
fun readLong() = stdin.readLong()
fun readLongs(n: Int) = LongArray(n){readLong()}
fun readDouble() = stdin.readDouble()
fun readDoubles(n: Int) = DoubleArray(n){readDouble()}
val stdout = PrintWriter(System.`out`)
val stdin = Scanner(System.`in`)
class Scanner(val input: InputStream){
val buf = ByteArray(4096)
var ptr = 0
var buflen = 0
val EOF = 0.toChar()
fun Byte.isPrintable() = this in 33..126
fun Char.isPrintable() = this.toInt() in 33..126
fun Char.toNum() = this - '0'
fun hasNextByte() = if(ptr < buflen) true else {
ptr = 0
buflen = input.read(buf)
buflen > 0
}
fun readChar() = if(hasNextByte()) buf[ptr++].toChar() else EOF
fun skip(){
while(hasNextByte() && !buf[ptr].isPrintable()) ptr++
if(!hasNextByte()) error("reached to EOF")
}
fun readLine() = buildString{
skip()
var c = readChar()
while(c != EOF && !c.isISOControl()){
append(c)
c = readChar()
}
}
fun readString() = buildString{
skip()
var c = readChar()
while(c != EOF && c.isPrintable()){
append(c)
c = readChar()
}
}
fun readLong(): Long {
skip()
var n = 0L
var neg = false
var c = readChar()
if(c == '-'){
neg = true
c = readChar()
}
while(c != EOF && c.isPrintable()){
if(!c.isDigit()) throw NumberFormatException()
n *= 10L
n += c.toNum()
c = readChar()
}
return if(neg) -n else n
}
fun readInt() = readLong().let{
if(it in Int.MIN_VALUE..Int.MAX_VALUE) it.toInt()
else throw NumberFormatException("$it is out of Int range")
}
fun readDouble(): Double {
skip()
var n = 0.0
var neg = false
var c = readChar()
if(c == '-'){
neg = true
c = readChar()
}
while(c != EOF && c.isDigit()){
if(c == '.') break
if(!c.isDigit()) throw NumberFormatException()
n = n * 10 + c.toNum()
c = readChar()
}
if(c == '.'){
var denom = 10.0
c = readChar()
while(c != EOF && c.isPrintable()){
if(!c.isDigit()) throw NumberFormatException()
n += c.toNum() / denom
denom *= 10L
c = readChar()
}
}
return if(neg) -n else n
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment