-
-
Save theodoreLee/becec43946cc25ae031c to your computer and use it in GitHub Desktop.
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
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