Created
December 9, 2011 14:46
-
-
Save giuniu/994e21f5d04bce98c165 to your computer and use it in GitHub Desktop.
ダブり文字列並べ替えロジック Scala版
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object SortWords { | |
def main(args: Array[String]): Unit = { | |
val list = args.toList sort (_ > _) | |
val foldList = (List((1, list.head)) /: list.tail) { | |
case (x, y) if (x.head._2 == y) => (x.head._1 + 1, x.head._2) :: x.tail | |
case (x, y) => (1, y) :: x | |
} | |
val result = foldList sort ((a, b) => a._1 > b._1 || a._1 == b._1 && a._2 < b._2) map (_._2) | |
println(result) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment