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

Super macros

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 129    Accepted Submission(s): 7


Problem Description
SuperHacker is a advanced Hacker. He often write GNU style macros to optimize the programs. One day pooorman gave him a batch of ugly style c code using nested ternary operator (? :), which makes the code difficult to comprehend.

Now SuperHacker turn to you for help, he have write a program to collect all the ugly code into a file, he send such file to you. Please write a utility to convert such file into a GNU C marcos header file.
 

Input
Input contains multiple valid (nested) c ternary operator expression. Each will be ended with a semicolon. There will be no empty expressions.
 

Output
For each case, generate a GNU C style macro function named with SuperHacker_functionn, n is the case num, which is started from 0. There should be a blank line between each case. Each case should be output as the Sample Output below.

Each line of the output should be indented well with tab(\t) as Sample output. The trailing line continuing symbol backslashs(\) macro end symbol '})' at the last line of a macro should be right aligned with tabs aligned. Each continuing symbol and macro end symbol '})' should be seperated with the code in such line with at least one tab indent. The tab symbol considered 8 word width.

To make the macro file includable, you should add some code to prevent multiple including at the begin and end of the output file, Same as the sample output below.

You should trim the redundancy parenthesis.
 

Sample Input
a? b: c; ((a)? b: c)? (d): e; ( welcome_to_acm_icpc_online_judge ) ;
 

Sample Output
#ifndef MACROS_H #define MACROS_H #define SuperHacker_function0() \ ({ int _r; \ if (a) \ _r = b; \ else \ _r = c; \ _r; }) #define SuperHacker_function1() \ ({ int _r; \ if (a) \ { \ if (b) \ _r = d; \ else \ _r = e; \ } \ else \ { \ if (c) \ _r = d; \ else \ _r = e; \ } \ _r; }) #define SuperHacker_function2() \ ({ int _r; \ _r = welcome_to_acm_icpc_online_judge; \ _r; }) #endif /* MACROS_H */
 

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-11-22 12:00:42, Gzip enabled