Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Language: Code Formatting
Description Programmers are known to wage religious wars when issues of proper code formatting are discussed. When new team of programmers starts working on a project, it often brings slightly different code formatting style and wants to reformat old source code according to their own style. Moreover, inexperienced programmers often neglect the importance of good and consistent code style, thus complicating the work of their teammates and themselves. This situation creates thriving market for code formatting tools.
You are taking part in a proof-of-concept project for a new code formatting tool code named Salvation. This is only a pilot project aimed not for a practical usefulness, but to demonstrate your ability to parse and format code of a high-level language. Your task is to write code formatter for a language called TRIVIAL (The Rival Implementation-Agnostic Language). This language has trivial lexical and grammatical structures. It does not have any keywords and control structures, because all constructs of the language are represented as function calls and closures. The lexical structure consists of identifiers, opening and closing parenthesis and curly braces, commas, and semi-colons. Identifiers consist only of digits '0'-'9' and Latin letters 'a'-'z', 'A'-'Z'. Lexical terms may be separated by whitespaces, leading and trailing whitespaces in the file are also allowed. Whitespace may consist of spaces, tab characters (ASCII code 9), and line separators (a pair of ASCII 13, 10). The structure of the valid trivial program is derived from the following productions:
Properly formatted trivial program additionally conforms to the following rules:
See sample output section for an example of properly formatted trivial program. Input The input contains valid trivial program. Size of each case does not exceed 2000 bytes. Output Write to the output file properly formatted trivial code for the program given in the input file. Sample Input {class(Point) { member ( int ( x ) ) ; member ( int ( y ) ) ; member ( fun ( Length ) { return ( sqrt ( sum ( sqr ( x ),sqr ( y ) ) ) ); } ) ; }; Main { repeat { set ( n,input ( int ) ) ; for ( int ( i,0 ) , lt ( i,n ) , inc ( i ) ) { print ( mult ( n,n ) ) ; }; }; }; } Sample Output { class(Point) { member(int(x)); member(int(y)); member(fun(Length) { return(sqrt(sum(sqr(x), sqr(y)))); }); }; Main { repeat { set(n, input(int)); for(int(i, 0), lt(i, n), inc(i)) { print(mult(n, n)); }; }; }; } Source |
[Submit] [Go Back] [Status] [Discuss]
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator