Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import scala.io.StdIn
- object Solution {
- def main(args: Array[String]): Unit = {
- def getArrayFromUI(current: Array[Array[Int]], remainTime: Int): Array[Array[Int]] = {
- if (remainTime == 0) current
- else {
- val x = StdIn.readLine().split(" ").map(_.toInt)
- getArrayFromUI(current :+ x, remainTime-1)
- }
- }
- def multiply(arrayA: Array[Array[Int]], arrayB: Array[Array[Int]]) =
- (for {
- zipped <- arrayA.zip(arrayB)
- (t1, t2) <- zipped._1.zip(zipped._2)
- } yield {
- t1 * t2
- }).sum
- val arrayA = getArrayFromUI(Array(), 6)
- val hourGlass = Array(Array(1, 1, 1), Array(0, 1, 0), Array(1, 1, 1))
- val steps = arrayA.length - hourGlass.length + 1
- val results = for {
- i <- (0 until steps).toArray
- j <- (0 until steps).toArray
- } yield {
- val a = arrayA.slice(i, i + 3).map(_.slice(j, j + 3))
- multiply(a, hourGlass)
- }
- println(results.max)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement