Skip to content

Instantly share code, notes, and snippets.

@theodoreLee
Created August 14, 2015 13:31
Show Gist options
  • Save theodoreLee/becec43946cc25ae031c to your computer and use it in GitHub Desktop.
Save theodoreLee/becec43946cc25ae031c to your computer and use it in GitHub Desktop.
import java.io.FileOutputStream
import scala.io.Source
object SmoothingWindow {
def solve(in: Seq[String]) = {
val Array(n,k) = in.head.split(" ").map(_.toInt)
val list = in(1).split(" ").map(_.toInt)
val ret = (k until n).foldLeft(Array.fill[Int](n)(0)) {
case (arr, i) =>
arr(i) = arr(i - k) + list(i- k + 1) - list(i - k)
arr
}
println(ret.mkString(","))
1
}
def main(args: Array[String]): Unit = {
val INPUT = "test.in"
val OUTPUT = INPUT.takeWhile(_ != '.') + ".out"
val isConsole = true
val itr = Source.fromFile(INPUT).getLines()
val stream = if (isConsole) Console.out else new FileOutputStream(OUTPUT)
try {
Console.withOut(stream) {
val sets = itr.next().toInt
(1 to sets).foreach { set =>
val seq = Seq(itr.next(),itr.next())
println(f"Case #$set: ${solve(seq)}")
}
}
} finally {
stream.flush()
if (!isConsole) stream.close()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment