Guest User

Untitled

a guest
Mar 24th, 2012
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 1.03 KB | None | 0 0
  1. import java.util.StringTokenizer
  2.  
  3. /**
  4.  *
  5.  * @author Vladislav Isenbaev ([email protected])
  6.  */
  7.  
  8. object CFTemplateBak extends App {
  9.   val tokenizer = new StringTokenizer(_: String)
  10.  
  11.   var st: StringTokenizer = tokenizer("")
  12.  
  13.   class FromString[A](val f: String => A)
  14.  
  15.   implicit val string2int = new FromString(_.toInt)
  16.   implicit val string2long = new FromString(_.toLong)
  17.   implicit val string2double = new FromString(_.toDouble)
  18.   implicit val string2bigInt = new FromString(BigInt(_))
  19.  
  20.   def nextToken(): String = {
  21.     while (!st.hasMoreTokens) {
  22.       val line = Console.readLine()
  23.       if (line == null) return null
  24.       st = tokenizer(line)
  25.     }
  26.     st.nextToken()
  27.   }
  28.  
  29.   def next[A]()(implicit converter: FromString[A]): A = converter.f(nextToken())
  30.  
  31.   def nextSeq[A](len: Int = next[Int]())(implicit c: FromString[A]): Seq[A] = for (i <- 0 until len) yield next[A]()
  32.  
  33.   val n = next[Int]()
  34.   val k = next[Int]()
  35.  
  36.   val pairs = for (i <- 0 until n) yield (next[Int](), next[Int]())
  37.  
  38. }
Advertisement
Add Comment
Please, Sign In to add comment