Skip to content

Instantly share code, notes, and snippets.

@waynejo
Last active April 1, 2016 12:04
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 waynejo/aa7787158f4f2ccc2f3560eaf83c42ad to your computer and use it in GitHub Desktop.
Save waynejo/aa7787158f4f2ccc2f3560eaf83c42ad to your computer and use it in GitHub Desktop.
package Main
import java.io.{FileInputStream, FileOutputStream}
import scala.annotation.tailrec
import scala.io.StdIn
object Main extends App {
Console.setIn(new FileInputStream("example.in"))
Console.setIn(new FileInputStream("A-small-practice.in"))
Console.setOut(new FileOutputStream("A-small-practice.out"))
Console.setIn(new FileInputStream("A-large-practice.in"))
Console.setOut(new FileOutputStream("A-large-practice.out"))
def solve(prices:List[Long]): List[Long] = {
@tailrec
def _solve(prices:List[Long], acc:List[Long] = List()):List[Long] = prices match {
case Nil => acc
case (x :: xs) =>
_solve(xs diff List(x * 4 / 3), x +: acc)
}
_solve(prices).reverse
}
val cases = StdIn.readLine().toInt
(1 to cases) foreach { i => {
StdIn.readLine().toInt
val inputs = StdIn.readLine().split(" ").map(_.toLong).toList
println(s"Case #$i: ${solve(inputs).mkString(" ")}")
}}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment