Lisp to C
InterviewTime limit1sMemory limit1024 MB
Convert a nested Lisp function call, given as a single line, into the equivalent C function call syntax with commas and parentheses.
- Level
Medium4 of 10
- Topics
- Stack, String, Recursion, Implementation
- Solved
- No attempts yet
Problem
C is an old programming language from the 70s that is still widely used despite its age. In C, a call to a function named namn is written as namn(parameter1, parameter2, ..., parameterN). A parameter is either a variable (in our case a sequence of characters a-z) or a function call itself. For example, a complete function call can look like this:
a(b, c(d), e(f, g(h, i, j)))
A function call without parameters is written as funktion().
Lisp is another programming language, from the 50s. In Lisp, a call to a function named namn is written as (namn parameter1 parameter2 ... parameter N). Again, a parameter can be a variable or a function call. The C function call shown above can instead be written as
(a b (c d) (e f (g h i j)))
A function call without parameters is written as (funktion).
Why this language history? It turns out that judge Simon likes C but not Lisp. Judge Johan, on the other hand, likes Lisp but not C.
Simon got very upset when Johan wrote all his example solutions in Lisp, and wants to convert Johan's programs to C. Help Simon by writing a program that, given a function call in Lisp, converts it to a function call in C.
Input
The input consists of one line containing a correctly formatted function call in Lisp format, at most characters long. All parameters are separated by exactly one space, and there are no extra spaces where they are not needed.
Output
Print a single line with the function call converted to C format. Include one space after each comma, as in the examples.