Created
December 14, 2012 11:43
-
-
Save adilakhter/4284839 to your computer and use it in GitHub Desktop.
SPOJ 42: ADDREV
This file contains 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
// problem definition : https://www.spoj.com/problems/ADDREV/ | |
open System | |
let parseTuple() : int*int = | |
let line = Console.ReadLine().Split() | |
line.[0] |> int , line.[1] |> int | |
let reverseInt n = | |
let rec reverseInt' n acc = | |
let acc' = acc + (n%10) | |
match n with | |
| n when n >= 10 -> reverseInt' ((int)(n/10)) (acc'*10) | |
| n -> acc' | |
reverseInt' n 0 | |
let solveCase (n1,n2) = reverseInt (reverseInt n1 + reverseInt n2) | |
let rec solveCases i maxCases = | |
if i < maxCases then | |
parseTuple() | |
|> solveCase | |
|> printfn "%d" | |
solveCases (i + 1) maxCases // solving next case | |
let spoj42() = | |
match Console.ReadLine() |> Int32.TryParse with | |
| (true, i) when i > 0 -> solveCases 0 i | |
| _ -> () | |
spoj42() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment