import scala.collection.mutable
import scala.io.StdIn
import util.control.Breaks._
object test {
def main(args: Array[String]): Unit = {
// 获取输入
val cacheList = mutable
.Map(StdIn.readLine()
.split(",")
.map(elem => {
val cache = elem.split(":")
Tuple2(cache(0).toInt, cache(1).toInt)
})
.toMap.toSeq: _*) // 转为 mutable.Map
val taskList: List[Int] = StdIn.readLine().split(",").map(_.toInt).toList
// 记录结果
val res = new StringBuffer()
var flag = true
for (taskElem <- taskList) {
flag = false
breakable {
for (cacheElem <- cacheList) {
// 当有可分配的内存时,将内存分配出去
if (cacheElem._1 >= taskElem & cacheElem._2 > 0) {
// 覆盖原有的值
cacheList.put(cacheElem._1, cacheElem._2 - 1)
flag = true
break
}
}
}
res.append(s"$flag,")
}
// 输出结果
print(res.substring(0, res.length() - 1))
}
}
标签:StdIn,val,res,cache,内存,._,import
From: https://www.cnblogs.com/saowei/p/16620056.html