<PREV Problem:
NEXT>
Solved by 159 users: ...
UserDateAttemptTimeCMSC
sb3ar30 apr 2008Ruby1800.0296 
sb3ar26 apr 2008Ruby1700.0298 
sb3ar24 apr 2008Ruby1500.02101 
Madiyar_Tktl18 jan 2014Python2500.05190 
ap_nayak03 jan 2005Python2?.??251 
Madiyar_Tktl18 jan 2014Python700.05252 
Fat15 feb 2008Ruby1700.02259 
e2n28 sep 2008Python100.06259 
lodin30 sep 2007Perl700.06261 
zyxw27 jan 2005Python1?.??264 
asp13 jul 2007C++100.01351 
Aion25629 apr 2011C++500.01351 
pekava131 dec 2010C++200.01357 
Languages
C++
90
FPC
26
C
12
Java
9
Kylix
9
Python
6
Ruby
4
Haskell
1
Scheme
1
Perl
1
 > 
 > 
 > 
 > 
 > 
 > 
 > 
 > 
 > 
 > 

Disclosing of parentheses

Time limit = 1 second(s)

You should disclose parentheses in simple arithmetic expression without it's simplifying. This expression may consists of variables (characters from 'a' to 'z' in lower case), add signs ('+'), open and close parentheses ( '(' and ')' ), and multiplying without sings. For example:

(a+b)(c+d)e+f

You should know that

1) ab ≠ ba.

2) expand braces starting with the leftmost expression:

(a+b)(c+d)  = ac + ad + bc + bd,
but
(a+b)(c+d) ≠ ac + bc + ad + bd.

Input: One line with Expression. The expression has less then 200 characters.

Output: You should open parentheses and output the result. If there is an error in the input expression then output "#ERROR".

Input#1
(a+b+c)(a+b+f)
Output#1
aa+ab+af+ba+bb+bf+ca+cb+cf
Input#2
(a+c)ab
Output#2
aab+cab
Input#3
()
Output#3
Input#4
(+a)
Output#4
#ERROR
Input#5
((a)
Output#5
#ERROR

Author:
Semi-final of Ukraine student olympiad, Khmelnitsky, march 2003.
24 april 2003

<PREV | Problem set | Search related messages | NEXT>


© acm.mipt DevGroup
The page was generated in 200ms

SW soft NIX
ID = 3.95.139.100