急にStandard MLしたくなったので。文字literalが#"c"なのが独特。

implementation

fun solve(#"H", b) = b
|   solve(#"D", #"H") = #"D"
|   solve(#"D", #"D") = #"H"

fun readChar() = TextIO.scanStream Char.scan TextIO.stdIn
val SOME a = readChar()
val SOME #" " = readChar()
val SOME b = readChar()
val () = print(Char.toString(solve(a, b)) ^ "\n")