首页 > ACM题库 > HDU-杭电 > hdu 3997 Super macros待解决[解题报告]C++
2015
04-14

hdu 3997 Super macros待解决[解题报告]C++

Super macros

问题描述 :

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 contains multiple valid (nested) c ternary operator expression. Each will be ended with a semicolon. There will be no empty expressions.

输出:

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

样例输入:

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

样例输出:

#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 */