結果

問題 No.185 和風
ユーザー noriocnorioc
提出日時 2015-08-16 21:19:13
言語 Scala(Beta)
(3.4.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 708 bytes
コンパイル時間 4,588 ms
コンパイル使用メモリ 223,664 KB
最終ジャッジ日時 2024-04-27 02:09:40
合計ジャッジ時間 4,911 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
-- [E040] Syntax Error: Main.scala:9:39 ----------------------------------------
9 |  def calc(xs: ListBuffer[(Int, Int)]) {
  |                                       ^
  |                                       '=' expected, but '{' found
-- [E040] Syntax Error: Main.scala:25:32 ---------------------------------------
25 |  def main(args: Array[String]) {
   |                                ^
   |                                '=' expected, but '{' found
2 errors found

ソースコード

diff #

import scala.collection.mutable.ListBuffer

object Main {
  val sc = new java.util.Scanner(System.in)
  def readLine(): String = sc.nextLine
  def readInts(): Array[Int] = sc.nextLine.split(' ').map(_.toInt)
  def readInt(): Int = sc.nextLine.toInt

  def calc(xs: ListBuffer[(Int, Int)]) {
    val n = xs.head._2 - xs.head._1
    if (n <= 0) {
      println(-1)
      return
    }

    for ((x, y) <- xs.tail) {
      if (n != y - x) {
        println(-1)
        return
      }
    }
    println(n)
  }

  def main(args: Array[String]) {
    val n = readInt
    val xs = new ListBuffer[(Int, Int)]
    for (i <- 0 to n-1) {
      val Array(x, y) = readInts
      xs.append((x, y))
    }
    calc(xs)
  }
}
0