POJ 1690 (Your)((Term)((Project)))
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 2912 | Accepted: 1084 |
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 <stdio.h>
#include <string.h>
#include <iostream>
using namespace std; int main()
{
char str[];
char str1[];
int pre[];
int visited[];
int del[];
int nCase;
scanf("%d", &nCase);
getchar();
while(nCase--)
{
gets(str);
memset(pre, , sizeof(pre));
memset(visited, , sizeof(visited));
memset(del, , sizeof(del));
int nLen = strlen(str);
int nCount = ;
for (int i = ; i < nLen; i++)
{
if (str[i] != ' ')
{
str1[nCount++] = str[i];
}
}
str1[nCount] = '\0';
nLen = strlen(str1);
for (int i = ; i < nLen; i++)
{
if (str1[i] == ')')
{
for (int j = i - ; j >= ; j--)
{
if (str1[j] == '(' && !visited[j])
{
pre[i] = j;
visited[j] = ;
break;
}
}
}
}
for (int i = ; i < nLen; i++)
{
if (str1[i] == ')')
{
int flag = ;
for (int j = i - ; j > pre[i]; j--)
{
if (str1[j] == '+' || str1[j] == '-')
{
flag = ;
break;
}
}
if (str1[pre[i]] == '(' && (str1[pre[i] - ] != '-' || pre[i] == || !flag))
{
del[i] = del[pre[i]] = ;
}
}
}
for (int i = ; i < nLen; i++)
{
if (!del[i])
{
printf("%c", str1[i]);
}
}
printf("\n");
}
return ;
}
POJ 1690 (Your)((Term)((Project)))的更多相关文章
- (Your)((Term)((Project)))
Description You have typed the report of your term project in your personal computer. There are seve ...
- POJ--1690 (Your)((Term)((Project)))(字符串处理)
(Your)((Term)((Project))) Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 3353 Accepted: ...
- 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 ...
- 专题:DP杂题1
A POJ 1018 Communication System B POJ 1050 To the Max C POJ 1083 Moving Tables D POJ 1125 Stockbroke ...
- poj 动态规划题目列表及总结
此文转载别人,希望自己能够做完这些题目! 1.POJ动态规划题目列表 容易:1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 11 ...
- poj动态规划列表
[1]POJ 动态规划题目列表 容易: 1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1208, 1276, 13 ...
- POJ 动态规划题目列表
]POJ 动态规划题目列表 容易: 1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1208, 1276, 1322 ...
随机推荐
- Codeforces 724 G Xor-matic Number of the Graph 线性基+DFS
G. Xor-matic Number of the Graph http://codeforces.com/problemset/problem/724/G 题意:给你一张无向图.定义一个无序三元组 ...
- 程序员的智囊库系列之2----网站框架(framework)
程序员的智囊库系列之2--网站框架(framework) 这是程序员的智囊库系列的第二篇文章.上一篇文章讲了服务器与运维相关的工具,这篇文章我们将介绍几个搭建网站的框架: django express ...
- APT和它的超级牛力
当你在使用apt时,例如“apt -h”会提示“本APT具有超级牛” 先把牛放一放,先学习以下关于APT的知识. APT 高级打包工具(英语:Advanced Packaging Tools,缩写为A ...
- 2018.3.31 java中的递归
java中的递归 1.概念 定义一个方法时,出现本方法调用本方法的过程,称之为递归 2.特点 必然有一个边界条件 使用递归代码往往更简洁,可读性强 3.什么时候使用递归 n的阶乘和n的累加定义 f(n ...
- tmpfs与内存盘
如何快速的吃掉一段内存:通过tmpfs来划一片领地,再用dd去粗暴占用mount -t tmpfs -o size=512M tmpfs /mnt/demodd if=/dev/zero of=/mn ...
- PAT (Basic Level) Practise (中文)- 1008. 数组元素循环右移问题 (20)
一个数组A中存有N(N>0)个整数,在不允许使用另外数组的前提下,将每个整数循环向右移M(M>=0)个位置,即将A中的数据由(A0A1……AN-1)变换为(AN-M …… AN-1 A0 ...
- sql server 定时备份 脚本
) DECLARE @date DATETIME SELECT @date = GETDATE() SELECT @filename = 'G:\backup\NewPlulishSQL-' + CA ...
- iOS8之后,UITableViewRowAction实现滑动多个按钮
#pragma mark - View lifeCycle - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = ...
- 概括的描述一下Spring注册流程
Spring经过大神们的构思.编码,日积月累而来,所以,对其代码的理解也不是一朝一夕就能快速完成的.源码学习是枯燥的,需要坚持!坚持!坚持!当然也需要技巧,第一遍学习的时候,不用关注全部细节,不重要的 ...
- 【windows】win7 sp1 系统语言中英文切换
注:Windows 7 Ultimate and Windows 7 Enterprise (旗舰版和企业版) 可以直接在控制面板/地区和语言中修改显示语言,其他系统不行 进入网站下载相关的MUI包安 ...