Last active
April 1, 2016 12:04
-
-
Save waynejo/aa7787158f4f2ccc2f3560eaf83c42ad 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
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