Guest User

Untitled

a guest
Jul 14th, 2018
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 1.21 KB | None | 0 0
  1. import java.io.BufferedReader
  2. import java.util.StringTokenizer
  3.  
  4. /**
  5.  *
  6.  * @author Vladislav Isenbaev (vladislav.isenbaev@odnoklassniki.ru)
  7.  */
  8.  
  9. object CFTemplate extends App {
  10.  
  11.   def main() {
  12.  
  13.   }
  14.  
  15.   class Tokenizer(in: BufferedReader, pattern: String = " \t\n\r\f") {
  16.     private def tokenizer = new StringTokenizer(_:String, pattern)
  17.     var st: StringTokenizer = tokenizer("")
  18.     def nextLine() = in.readLine()
  19.     def nextToken(): String = {
  20.       while (!st.hasMoreTokens) {
  21.         val line = nextLine()
  22.         if (line == null) return null
  23.         st = tokenizer(line)
  24.       }
  25.       st.nextToken()
  26.     }
  27.     def next[A](f: String => A): A = f(nextToken())
  28.   }
  29.  
  30.   implicit val tokenizer = new Tokenizer(Console.in)
  31.  
  32.   implicit def nextInt()(implicit t: Tokenizer) = t.next(_.toInt)
  33.   implicit def nextLong()(implicit t: Tokenizer) = t.next(_.toLong)
  34.   implicit def nextDouble()(implicit t: Tokenizer) = t.next(_.toDouble)
  35.   implicit def nextBigInt()(implicit t: Tokenizer) = t.next(BigInt(_))
  36.   implicit def nextString()(implicit t: Tokenizer) = t.next(identity[String])
  37.  
  38.   def nextSeq[A](len: Int = nextInt())(implicit c: () => A): Seq[A] = for (i <- 0 until len) yield c()
  39.  
  40.   main()
  41. }
Add Comment
Please, Sign In to add comment