(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 ...
随机推荐
- ARM中的总线
ARM中的总线用于不同部件之间的通信.有两种不同类型的设备连接到总线:ARM处理器,它是总线的主设备,拥有对总线的仲裁权,可以通过同一总线主动发起数据传输请求:外围器件,是总线的从设备,在总线上是被动 ...
- 解决li在ie,firefox中行高不一致问题
转载 http://www.cnblogs.com/jikey/archive/2011/11/13/2247543.html li在ie与firefox的高度是不一样的,解决办法是li font-s ...
- struts2视频学习笔记 21(输入校验的流程)
课时21 输入校验的流程 1.类型转换器对请求参数执行类型转换,并把转换后的值赋给action中的属性. 2.如果在执行类型转换的过程中出现异常,系统会将异常信息保存到ActionContext,co ...
- nyoj-746
整数划分(四) 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 暑假来了,hrdv 又要留学校在参加ACM集训了,集训的生活非常Happy(ps:你懂得),可是他最近 ...
- Error in Android Studio - "Default Activity Not Found"
Make sure you have specified the default activity in your AndroidManisfest.xml file. Within your def ...
- python——使用readline库实现tab自动补全
Input History readline tracks the input history automatically. There are two different sets of funct ...
- 你所知道的Java单例模式并不是单例模式
当我们搜索单例模式的时候,能看到很多例子,什么懒汉式.饿汉式,大概如下: public class Singleton { private static Singleton instance=null ...
- 使用MediaRecorder录制视频短片
MediaRecorder除了可用于录制音频之外,还可用于录制视频,使用MediaRecorder录制视频与录制音频的步骤基本相同.只是录制视频时不仅需要采集声音,还需要采集图像.为了让MediaRe ...
- EntLib Unity父类的依赖注入问题
Unity的注入有3种方式:构造函数.[Dependency]属性.[InjectionMethod]方法.这3种方式涉及到的interface或class都会去Registrations里找,找不到 ...
- 【HDU2087】KMP
KMP算法其实很好理解,就是在匹配串中找最近的相同的串. 下面是HDU的2087: #include<iostream> #include<cstdio> #include&l ...