package Yukicoder import java.util.regex.Pattern /** * Created by hichikawa on 2015/11/12. */ fun main(args: Array) { fun readLineLongArray(): List { val str = readLine() as String val arrStr = str.split(" ") val ret = arrStr.map { it.toLong() } return ret } fun readLineLong(): Long { val str = readLine() as String return str.toLong() } fun readLineInt(): Int { val str = readLine() as String return str.toInt() } fun readLineIntArray() : List { val str = readLine() as String val arrStr = str.split(" ") val ret = arrStr.map { it.toInt() } return ret } fun readLineDoubleArray(): List { val str = readLine() as String val arrStr = str.split(" ") val ret = arrStr.map { it.toDouble() } return ret } var str = readLine() as String val pTasu : Pattern = Pattern.compile("^(\\d+)\\+(\\d+)") val pKake : Pattern = Pattern.compile("^(\\d+)\\*(\\d+)") // val p : Pattern = Pattern.compile("(\\d+)\\+") while (true) { val mTasu = pTasu.matcher(str) if (mTasu.find()) { str = mTasu.replaceFirst((mTasu.group(1).toInt()*mTasu.group(2).toInt()).toString()) // println(str) continue } val mKake = pKake.matcher(str) if (mKake.find()) { str = mKake.replaceFirst((mKake.group(1).toInt()+mKake.group(2).toInt()).toString()) // println(str) continue } break } println(str) }