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 ...
随机推荐
- linux系统及服务安全(持续更新中)
linux安全 1.隐藏NGINX和PHP版本号 curl -I "http://www.xxx.com" //检测 nginx: http段加入server_tokens of ...
- jsp之获传统方式取后台数据
1.建立模型对象: package com.java.model; public class Student { private String name; private int age; publi ...
- SG函数入门&&HDU 1848
SG函数 sg[i]为0表示i节点先手必败. 首先定义mex(minimal excludant)运算,这是施加于一个集合的运算,表示最小的不属于这个集合的非负整数.例如mex{0,1,2,4}=3. ...
- JS给数字加千位分隔符
本文原链接:https://www.jianshu.com/p/928c68f92c0c JavaScript实现千位分隔符 将普通的数字转换为带千位分隔符格式的数字字符串是一个非常常见的问题,千位分 ...
- python之生成器的初识
1. 生成器的定义 生成器的本质就是迭代器.python社区生成器和迭代器是一种 2. 生成器和迭代器区别 迭代器: 都是Python给你提供的已经写好的工具或者通过数据转化得来的 生成器: ...
- Dojo的define接口
http://blog.csdn.net/lovecarpenter/article/details/53979717 第三种用法用的最多. 此接口用于定义模块: define([],function ...
- java,求1-100以内所有偶数的和。
package study01; public class Even { public static void main(String[] args) { int sum = 0; for (int ...
- iOS 后台传输服务
后台传输服务 — 我们用水壶来比喻 (0:14) 后天传输服务是 iOS 7 引进的 API,它准许应用暂停或者中止之后,在后台继续执行网络服务(比如下载或者上传).举个例子,这正是 Dropbox ...
- JavaScript中数组的使用
---恢复内容开始--- 创建数组 1,通过 var arr1 = [1,2,3] 2通过使用 var arr2 = new Array(1,2,3) 在这里创造的数组实际上都是一个对象,然后把对象的 ...
- 字节跳动后端开发实习生面试(Python)
一面: 1.自我介绍. 2.介绍“工大小美”项目相关. 3.Python中的GIL(全局解释器锁),以及哪种情况下使用python的多线程性能有较大的提升. 4.项目中用到了SQLite数据库,如果有 ...