Skip to content

Instantly share code, notes, and snippets.

@giuniu
Created December 9, 2011 14:46
Show Gist options
  • Save giuniu/994e21f5d04bce98c165 to your computer and use it in GitHub Desktop.
Save giuniu/994e21f5d04bce98c165 to your computer and use it in GitHub Desktop.
ダブり文字列並べ替えロジック Scala版
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