Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. import scala.io.StdIn
  2.  
  3. object Solution {
  4. def main(args: Array[String]): Unit = {
  5.  
  6. def getArrayFromUI(current: Array[Array[Int]], remainTime: Int): Array[Array[Int]] = {
  7. if (remainTime == 0) current
  8. else {
  9. val x = StdIn.readLine().split(" ").map(_.toInt)
  10. getArrayFromUI(current :+ x, remainTime-1)
  11. }
  12. }
  13.  
  14. def multiply(arrayA: Array[Array[Int]], arrayB: Array[Array[Int]]) =
  15. (for {
  16. zipped <- arrayA.zip(arrayB)
  17. (t1, t2) <- zipped._1.zip(zipped._2)
  18. } yield {
  19. t1 * t2
  20. }).sum
  21.  
  22.  
  23. val arrayA = getArrayFromUI(Array(), 6)
  24. val hourGlass = Array(Array(1, 1, 1), Array(0, 1, 0), Array(1, 1, 1))
  25. val steps = arrayA.length - hourGlass.length + 1
  26.  
  27. val results = for {
  28. i <- (0 until steps).toArray
  29. j <- (0 until steps).toArray
  30. } yield {
  31. val a = arrayA.slice(i, i + 3).map(_.slice(j, j + 3))
  32. multiply(a, hourGlass)
  33. }
  34.  
  35. println(results.max)
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement