(Your)((Term)((Project)))
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 3353 Accepted: 1256 DescriptionYou have typed the report of your term project in your personal computer. There are several one line arithmetic expressions in your report. There is no redundant parentheses in the expressions (omitting a pair of redundant matching parentheses does not change the value of the expression). In your absence, your little brother inserts some redundant matching parentheses in the expressions of your report. Assume that the expressions remain syntactically correct and evaluate to their original value (the value before inserting redundant parentheses). To restore your report to its original form, you are to write a program to omit all redundant parentheses.
To make life easier, consider the following simplifying assumptions: The input file contains a number of expressions, each in one separate line. Variables in the expressions are only single uppercase letters. Operators in the expressions are only binary ‘+’ and binary ‘-‘.Note that the only transformation allowed is omission of redundant parentheses, and no algebraic simplification is allowed.
InputThe input consists of several test cases. The first line of the file contains a single number M, which is the number of test cases (1 <= M <= 10). Each of the following M lines, is exactly one correct expression. There may be arbitrarily space characters in each line. The length of each line (including spaces) is at most 255 characters.
OutputThe output for each test case is the same expression without redundant parentheses. Notice that the order of operands in an input expression and its corresponding output should be the same. Each output expression must be on a separate line. Space characters should be omitted in the output expressions.
Sample Input3
(A-B + C) - (A+(B - C)) - (C-(D- E) ) ((A)-( (B))) A-(B+C) Sample OutputA-B+C-(A+B-C)-(C-(D-E))
A-B A-(B+C)1:括号前面是不是减号
2:最外层的括号 3:括号前面是减号,但是括号之间没有加减运算的符的 满足以上条件的去掉。#include#include #include #include #include #include using namespace std;char a[300];char b[300];int tag[300];int flag[300];int len;stack s;int find(int num){ int res=0; for(int i=0;i