import java.util.Scanner object Problem193 { def main(args: Array[String]) { val sc = new Scanner(System.in) val s = sc.next // 1文字ずつ回転 val results = for (i <- 0 until s.length) yield { val (pre, post) = s.splitAt(i) val rolledStr = post + pre val values: Array[String] = rolledStr.split("[+-]") val ops: Array[Char] = '+' +: rolledStr.filter(!_.isDigit).toArray if (values.length == ops.length && !values.contains("")) { val exprs: Array[(String, Char)] = values.zip(ops) val res = for (expr <- exprs) yield { expr match { case (x, '+') => x.toInt case (x, '-') => -x.toInt } } Some(res.sum) } else { None } } println(results.max.get) } }