(Your)((Term)((Project)))
Description
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
Output
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<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
const int N=;
int vis[N],kk[N];
char a[N],str[N];
int main()
{
int t;
scanf("%d",&t);
getchar();//吸收回车键
while(t--)
{
gets(a);//读入整行,以\n或EOF为结束
//scanf("%s",a);
memset(vis,,sizeof(vis));
memset(kk,-,sizeof(kk));
int i,j;
for(i=,j=;a[i];i++)
if(a[i]!=' ') str[j++]=a[i];
str[j]=;
for(i=;str[i];i++)
{
if(str[i]==')'&kk[i]==-)
{
for(j=i-;j>=;j--)
{
if(str[j]=='('&&vis[j]==)
{
kk[i]=j;
vis[j]=;break;
}
}
// vis[i]=1;
} }
int flag,del[N];
memset(del,,sizeof(del)); for(i=;str[i];i++)
{
if(!del[i]&&str[i]==')')
{
flag=;
for(j=i-;j>kk[i];j--) if(str[j]=='+'||str[j]=='-')
{
flag=;break;
}
if(kk[i]==||str[kk[i]-]=='-'&&flag==||str[kk[i]-]!='-')
del[kk[i]]=,del[i]=; }
}
for( i=;str[i];i++)
{
if(del[i]) continue;
printf("%c",str[i]);
}
printf("\n"); }
return ;
}
(Your)((Term)((Project)))的更多相关文章
- POJ--1690 (Your)((Term)((Project)))(字符串处理)
(Your)((Term)((Project))) Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 3353 Accepted: ...
- POJ 1690 (Your)((Term)((Project)))
(Your)((Term)((Project))) Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 2912 Accept ...
- Tarjan UVALive 6511 Term Project
题目传送门 /* 题意:第i个人选择第a[i]个人,问组成强联通分量(自己连自己也算)外还有多少零散的人 有向图强联通分量-Tarjan算法:在模板上加一个num数组,记录每个连通分量的点数,若超过1 ...
- UVALive 6511 Term Project
Term Project Time Limit: 3000ms Memory Limit: 131072KB This problem will be judged on UVALive. Origi ...
- ZOJ 1423 (Your)((Term)((Project))) (模拟+数据结构)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=423 Sample Input 3(A-B + C) - (A+(B ...
- Storm(3) - Calculating Term Importance with Trident
Creating a URL stream using a Twitter filter Start by creating the project directory and standard Ma ...
- Distributed Databases and Data Mining: Class timetable
Course textbooks Text 1: M. T. Oszu and P. Valduriez, Principles of Distributed Database Systems, 2n ...
- 别人整理的DP大全(转)
动态规划 动态规划 容易: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ...
- dp题目列表
此文转载别人,希望自己能够做完这些题目! 1.POJ动态规划题目列表 容易:1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 11 ...
随机推荐
- 190. Reverse Bits -- 按位反转
Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented in ...
- 51nod 1043 幸运号码(数位dp)
题目链接:51nod 1043 幸运号码 题解:dp[i][j]表示 i 个数和为 j 的总数(包含0开头情况) dp[i][j] = dp[i-1][j-k] i & 1 :这里用滚动数组节 ...
- java 分析方法调用过程
StackTraceElement[] s = new Exception().getStackTrace(); for(int i=0;i<s.length;i++) System.out.p ...
- Snappy压缩
Snappy压缩时,碰到不能解压问题,所用服务器Tomcat8.经验证,降低Tomcat版本为7,才可正常解压文件. 若碰到偶尔不能解压的问题,试着换个浏览器试试.
- Computer Science Courses – Yan Yan
CS: Compilers / Programming Languages Course Title Fundamentals of C++ Language Programming Textbook ...
- qml操作播放器
现在增加了一个filter属性,所以可以很好和opencv结合.转一篇文章(http://blog.qt.io/blog/2015/03/20/introducing-video-filters-in ...
- 关于职位的解释---转CSDN的文章
摘要我在IT职场打滚超过15年了,从小小的程序员做到常务副总.相对于其它行业,IT职场应该算比较光明的了,但也陷阱重重,本文说说我的亲身体会,希望大家能在IT职场上战无不胜! 通用法则 法则1:忍耐是 ...
- C#中三种定时器对象的比较
·关于C#中timer类 在C#里关于定时器类就有3个1.定义在System.Windows.Forms里2.定义在System.Threading.Timer类里3.定义在System.Timers ...
- STM32-AFIO
只有使用了AFIO的事件控制寄存器.AFIO的重映射功能以及外部中断(EXTI)控制寄存器才需要开启AFIO的时钟,STM32参考手册从来没说过使用IO的复用功能就一定要开启AFIO时钟,这是个误区.
- CSS盒子模型和IE浏览器
CSS盒模型图解 下面是一幅关于应用了CSS的元素是如何显示它的尺寸的图示. 在本篇文章中,所有的浏览器在计算盒模型总宽度时处理margin属性的方式都是一致的,所以我们将更多的精力放在padding ...