結果
問題 | No.24 数当てゲーム |
ユーザー |
|
提出日時 | 2016-12-24 23:18:35 |
言語 | Scala(Beta) (3.6.2) |
結果 |
AC
|
実行時間 | 929 ms / 5,000 ms |
コード長 | 1,428 bytes |
コンパイル時間 | 10,018 ms |
コンパイル使用メモリ | 273,096 KB |
実行使用メモリ | 65,884 KB |
最終ジャッジ日時 | 2024-06-29 21:59:00 |
合計ジャッジ時間 | 20,669 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 10 |
ソースコード
import scala.collection.mutableimport scala.io.StdIn/*** Created by Administrator on 2016/12/24 0024.*/object Sub {def intersection(arrSet: mutable.HashSet[Array[Int]]): mutable.HashSet[Int] = {var count = 0var set = new mutable.HashSet[Int]()for(arr<-arrSet){if(count==0){for(i<-arr){set.add(i)}}else{set={val tempSet = new mutable.HashSet[Int]()for(i<-arr){if(set.contains(i)){tempSet.add(i)}}tempSet}}count+=1}set}def intersection(intSet: mutable.HashSet[Int], numbers: mutable.TreeSet[Int]): Int = {for(i<-numbers){if(intSet.contains(i)){return i}}return -1}}object Main extends App {val numbers = new mutable.TreeSet[Int]()for (i <- 0 to 9) {numbers += i}val count = StdIn.readInt()val yesSet = new mutable.HashSet[Array[Int]]()for (_ <- 1 to count) {val input = StdIn.readLine().split(" ")val array = input.toList.slice(0, 4).toArray.map(i => i.toInt)if (input.last == "YES") {yesSet.add(array)}else {for (i <- array) {numbers.remove(i)}}}if (yesSet.size > 0) {println(Sub.intersection(Sub.intersection(yesSet), numbers))} else {println(numbers.toArray.apply(0))}}