import java.util.Scanner import scala.util.Sorting object Problem267 { case class Card(kind: String) object CardOrdering extends Ordering[Card] { def compare(a: Card, b: Card) = { val ca = formatComparableFormat(a) val cb = formatComparableFormat(b) ca compare cb } def formatComparableFormat(c: Card): Int = { val mark: Int = c.kind.splitAt(1)._1 match { case "D" => 1 case "C" => 2 case "H" => 3 case "S" => 4 } val number: Int = c.kind.splitAt(1)._2 match { case "A" => 1 case "T" => 10 case "J" => 11 case "Q" => 12 case "K" => 13 case x => x.toInt } mark * 100 + number } } def main(args: Array[String]) { val sc = new Scanner(System.in) val n = sc.nextInt val cards = Array.fill(n)(Card(sc.next)) Sorting.quickSort(cards)(CardOrdering) println(cards.map(_.kind).mkString(" ")) } }