Last active
December 15, 2015 15:49
-
-
Save kazua/5284645 to your computer and use it in GitHub Desktop.
世界で闘うプログラマ本の1-7
This file contains hidden or 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
| //write Kazua | |
| import scala.collection.mutable._ | |
| object worldproblem1_7 { | |
| def ZeroUpdate(tgt : Array[Array[Int]]) = { | |
| val rowbol = Map[Int, Int]() | |
| val colbol = Map[Int, Int]() | |
| for (i <- 0 until tgt.size) { | |
| rowbol(i) = 1 | |
| for (j <- 0 until tgt(i).size) | |
| if (tgt(i)(j) == 0) { | |
| rowbol(i) = 0 | |
| colbol(j) = 0 | |
| } else if (!colbol.contains(j)) colbol(j) = 1 | |
| } | |
| for (i <- 0 until tgt.size) | |
| for (j <- 0 until tgt(i).size) | |
| if (rowbol(i) * colbol(j) == 0) | |
| tgt(i)(j) = 0 | |
| tgt | |
| } | |
| def main(args : Array[String]) { | |
| ZeroUpdate( | |
| Array( | |
| Array(1, 4, 7, 9, 4, 5, 6, 3, 5, 6, 3, 1, 6, 8), | |
| Array(2, 3, 5, 7, 2, 4, 9, 0, 1, 2, 4, 5, 1, 9), | |
| Array(5, 3, 2, 7, 6, 1, 4, 1, 8, 9, 3, 2, 1, 6), | |
| Array(3, 3, 3, 1, 6, 8, 4, 2, 8, 4, 2, 4, 6, 3))).foreach(a => { | |
| a.foreach(print) | |
| println | |
| }) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment