Advertisement
Guest User

Untitled

a guest
Apr 28th, 2015
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.76 KB | None | 0 0
  1. import java.io.{PrintWriter, FileWriter}
  2.  
  3. import scala.annotation.tailrec
  4. import scala.io.StdIn
  5.  
  6. object Main extends App {
  7.   GenFilesFromWAP(StdIn.readInt,StdIn.readLine)
  8. }
  9.  
  10. object GenFilesFromWAP{
  11.   def apply(n:Int,output:String): Unit ={
  12.     val wap = scala.io.Source.fromFile(new java.io.File( "." ).getCanonicalPath+"/ВИМ/ВИМ.txt","UTF-8").mkString
  13.     @tailrec
  14.     def f(i:Int,s:String,l:List[(Int,String)]=List()): List[(Int,String)] ={
  15.       if(i==1) ((n-1,s)::l)
  16.       else {
  17.         val partL = scala.util.Random.nextInt(s.length/i)
  18.         f(i-1,s.drop(partL),(n-i,s.take(partL))::l)
  19.       }
  20.     }
  21.     for((i,s) <- f(n,wap)){
  22.       val out = new PrintWriter(new FileWriter(s"$output/$i.txt"))
  23.       out.print(s)
  24.       out.close()
  25.     }
  26.   }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement