博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ--1690 (Your)((Term)((Project)))(字符串处理)
阅读量:5009 次
发布时间:2019-06-12

本文共 2366 字,大约阅读时间需要 7 分钟。

(Your)((Term)((Project)))

Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 3353 Accepted: 1256
Description

You 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.

Input

The 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.

Output

The 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 Input

3

(A-B + C) - (A+(B - C)) - (C-(D- E) )
((A)-( (B)))
A-(B+C)
Sample Output

A-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

转载于:https://www.cnblogs.com/dacc123/p/8228830.html

你可能感兴趣的文章
学习web的road-map
查看>>
url模块和querystring模块
查看>>
.net core入门 部署到Linux实践
查看>>
WPF Bitmap转Imagesource
查看>>
Java compiler level does not match the version of the installed Java project facet.解决方法
查看>>
笔记_小结
查看>>
Linux lsof命令 umount U盘
查看>>
自定义Font
查看>>
Matlab绘制透明平面(二元函数)
查看>>
基于二部图的推荐
查看>>
POJ 1543
查看>>
linux svn 服务端搭建
查看>>
maven用途、核心概念、用法、常用参数和命令、扩展
查看>>
linux时间同步ntp服务的安装与配置
查看>>
django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE的解决办法...
查看>>
网络编程-socket并发-粘包问题
查看>>
Mitmproxy(Mitmdump) 二次代理使用方式启动python
查看>>
JSP 技术(二)--详解
查看>>
第二冲刺阶段——站立会议第十四天6月7日
查看>>
HDUOJ----Super Jumping! Jumping! Jumping!
查看>>