文字列の組合せScala版
630 ワード
object Combination{
def combinate(pre:String,m: Int,data: String){
data.foreach{ e =>
if(pre.length() == m-1){
if(!pre.contains(e))
println(pre+e)
}else{
if(!pre.contains(e))
combinate(pre+e,m,data)
}
}
}
def arrange(pre:String,m:Int,data:String){
data.foreach{
e =>
if(pre.length() == m-1)
println(pre+e)
else
arrange(pre+e,m,data)
}
}
def main(args: Array[String]){
// combinate("",3,"abc")
arrange("",2,"abc")
}
}