我有一个在本地工作的问题的代码,但当我上传到hackerearth时,我得到一个NZEC,代码结构如下:
import scala.annotation.tailrec
object SamuAndCardGame extends App {
case class Board(w: Long, h: Long) {
def validPos(v: Vec) = {
v.x >=1 && v.x <= w && v.y >= 1 && v.y <= h
}
}
case class Vec(x: Long, y: Long) {
def +(other: Vec) = {
Vec(this.x + other.x, this.y + other.y)
}
}
def validJumps(board: Board, jumps: Seq[Vec]) = {
@tailrec
def rec(currPos:Vec, jump:Int, count: Long): Long = {
if(jump >= jumps.size) count
else{
val newPos = currPos + jumps(jump)
if(board.validPos(newPos)) rec(newPos, jump , count + 1)
else rec(currPos, jump + 1, count)
}
}
rec(Vec(1,1), 0, 0)
}
val in = io.Source.stdin.getLines()
val tc = in.next.toInt
for(_ <- 1 to tc){
val Array(n, m)= in.next.split(" ").map(_.toInt)
val board = Board(m,n)
val k = in.next.toInt
var count = 0
val jumps = for(_ <- (1 to k)) yield {
val line = in.next
val Array(a, b) = line.split(" ").map(_.toLong)
Vec(a, b)
}
println(validJumps(board, jumps))
}
}
hackerearth关于运行时错误的输出如下:
java.lang.NoSuchMethodException: SamuAndCardGame$Vec.main([Ljava.lang.String;)
at java.lang.Class.getMethod(Class.java:1786)
at scala.reflect.internal.util.ScalaClassLoader$class.run(ScalaClassLoader.scala:66)
at scala.reflect.internal.util.ScalaClassLoader$URLClassLoader.run(ScalaClassLoader.scala:101)
at scala.tools.nsc.CommonRunner$class.run(ObjectRunner.scala:22)
at scala.tools.nsc.ObjectRunner$.run(ObjectRunner.scala:39)
at scala.tools.nsc.CommonRunner$class.runAndCatch(ObjectRunner.scala:29)
at scala.tools.nsc.ObjectRunner$.runAndCatch(ObjectRunner.scala:39)
at scala.tools.nsc.MainGenericRunner.runTarget$1(MainGenericRunner.scala:65)
at scala.tools.nsc.MainGenericRunner.run$1(MainGenericRunner.scala:87)
at scala.tools.nsc.MainGenericRunner.process(MainGenericRunner.scala:98)
at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:103)
at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)
我不明白为什么Hackerearth试图在内部类Vec而不是外部对象SamuAndCardGame上找到主要方法。
如果遇到类似问题的人会给我一些指导,我将不胜感激。