/* Problem #4 -- Stanford Local Programming Contest - 2003 Solution by manku@stanford.edu */ #include #include void handle(int w) { if (w == 0) printf ("\n") ; else if (w % 3 == 0) printf ("N"), handle (w/3) ; else if (w % 3 == 1) printf ("R"), handle ((w-1)/3) ; else printf ("L"), handle ((w+2)/3) ; return ; } int main(int argc, char *argv[]) { char w[2000] ; while (fscanf (stdin, "%s", &w[0]) == 1) printf ("%s = ", &w[0]), handle (atoi(w)) ; return 0 ; }