我有许多行作为输入,并希望读取和打印完全相同的内容。问题是我不知道怎么做!(readLine)输入来自用户输入终端。
第一个整数是总行数!
输入:
4
word
localization
internationalization输出:
word
localization
internationalization发布于 2020-11-02 06:01:08
就像这样
// default condition: string is not empty, not inclusive!
class TermLines (cond: (String => Boolean) = _ != "") extends Iterator[String] {
var s = readLine;
def hasNext = cond(s);
def next = { var r = s; s = readLine; r }
} 那就叫它吧
println((new TermLines).toVector.mkString("\n")) // till empty或
println(new TermLines(_.last != '.').toVector.mkString("\n")) // till last is dot发布于 2020-11-03 19:45:38
解决了!
import scala.io.StdIn
object Solution extends App
{
val numOfLines = StdIn.readInt()
def words: Seq[String] = for (_ <- 1 to numOfLines) yield StdIn.readLine()
def sort = words.map
{
case word => word
}
sort.foreach(println)
}https://stackoverflow.com/questions/64629461
复制相似问题