Skip to content

Instantly share code, notes, and snippets.

@yunyu
Created January 19, 2018 19:10
Show Gist options
  • Save yunyu/98845188faa076406adff9d7b438e735 to your computer and use it in GitHub Desktop.
Save yunyu/98845188faa076406adff9d7b438e735 to your computer and use it in GitHub Desktop.
let
type any = {any : int}
var buffer := " "
function readint() : int =
let var i := 0
var any := any{any=0}
function isdigit(s : string) : int =
ord(buffer)>=ord("0") & ord(buffer)<=ord("9")
function skipto() =
while buffer=" " | buffer="\n"
do buffer := getchar()
in skipto();
any.any := isdigit(buffer);
while isdigit(buffer)
do (i := i*10+ord(buffer)-ord("0"); buffer := getchar());
i
end
function printint(i: int) =
let function f(i:int) = if i>0
then (f(i/10); print(chr(i-i/10*10+ord("0"))))
in if i<0 then (print("-"); f(-i))
else if i>0 then f(i)
else print("0")
end
in
/* Your code here */
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment