F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Code Formatting

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 388    Accepted Submission(s): 46


Problem Description
As we all know, a piece of code may include variablefunction and some other program statements such as ifelsewhilefor, etc.  
Usually we cannot guarantee our code is absolutely right. When you didn't get the verdict - 'Accepted', you would start debugging. So in ACMICPC contests, we have team-mates to help us.  
When you copy a program to windows from linux and open it with notepad, you can see all in one line.
Of course, the code can be compiled with g++ on linux, but it's not formatted, so it's too hard to read it.
Now you are given a piece of code, and your task is to format the code to make it good.

To make it simple, we define the code only contain header filevariablefunctionifforprintfscanf, and expression(e.g. a = b + 1)  
Also a piece of code is called good if it obey as follows:
1. header file
      A space between #include and <XXX> is required. And XXX in <> can be any correct header file.
      You can only declare one header file in one line.
      It is guaranteed that all header files declaration are at the very beginning of the code.
      A blank line is required after all header files if header files exist.
2. variable declaration  
X A, B, C, ...;
      Assuming that X can be only intdoublebool or char, and there must be at least one space after X.
      You can only declare one type of variable in one line.
      The comma(,) is used to split variables in one type in one line. And a space is required after the comma(,).
      It is guaranted that there must be a space between X and A.
      ABC, ..., are the name of variable, and guarantee that no calculation, just declaration.
      The name of variable can be any except "scanf" and "printf".
3. function  
X Y(A a, B b, ...){}
      X is the type of the function, which can be 4 variables above plus void.
      Y is the name of the function, which can be any except "scanf" and "printf".
      A and B the type of variable a and b, and ab is the name which can be any.
      A space is required between X and YA and aB and b.
      ... means if the function have more parameters, the format is the same as above.
      There can be any parameters(0 included) in each function.
     It is guaranteed that there will be a space between X and Y.
A space is required after each ",".
4. if  
if(X){}
      X is an expression
      There must be { and } after if(X).
5. for  
for(X; Y; Z){}
      XYZ are three expressions split by ;, and a space is required after each ;.
      There must be { and } after for(X; Y; Z).
      X, Y, Z can be empty (e.g. for(; ; ), for(X; ; Z), for(; Y; ), etc)
6. printf  
printf("X", Y, Z, ...);
      X in "" is a string which you shouldn't change it.
      Y, Z, ... are expressions split by ,, and a space is required after each ",".
      The number of expressions can be 0 or more.
7. scanf  
scanf("X", &Y, Z, ...);
      Abosolutely the same with printf
8. expression  
      There could be variablesoperator(+-*/=<>>=<===!=) and some constant.
      For each operator, a space is required for both sides.
9. function
X(A, B, C, ...);
      You can call a function after your declaration.
      Especially, whatever the type your function is, there will be no return in function's {}.
      A, B, C, ... are expressions.
      Function call cannot appear in expressions. Although this may be rediculous, it's much more easier for your coding.
A space is required after each ",".

In addition, there can be many expressionsscanfprintvariable declaration inside {}  
{ and } should both take up one line.  
The rule inside {} is the same, but should start with two more space.

In all, all characters appear in your code can be only [a-z][A-Z][0-9]<>()\+-*/=!,;.%&#"' and space.

The sample involved all rules above. Just have a look at it to unstander better.

It is guaranteed that the code after formatting can be compiled by g++, so your task is only to format it!
 

Input
Multiple cases(no more than 100), each case is a piece of code in one line.
The length of each piece of code, which in one line, is no more than 1000.
 

Output
For each case, please output Case #k: in one line first, which k starts from 1.
And then please output the code which is called good.
 

Sample Input
2 #include #include #includeint max;void Solve(int a,int b){ if ( a>max){max=a;} if ( b > max){max=b;}} int n,m;double x;int main() {scanf("%d", &n); int i;for(i=0; i int main(){printf("\"");}
 

Sample Output
Case #1: #include #include #include int max; void Solve(int a, int b) { if(a > max) { max = a; } if(b > max) { max = b; } } int n, m; double x; int main() { scanf("%d", &n); int i; for(i = 0; i < n; i = i + 1) { int a; a = i + 1; printf("a=%d", a); Solve(i, i + 1); } printf("%d\n", max); printf("example with no parameter."); } Case #2: #include int main() { printf("\""); }
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-04-16 17:59:48, Gzip enabled