ZOJ Problem Set - 1423 (Your)((Term)((Project)))
2011-10-19 20:43
447 查看
一道比较好的题,对栈和队列有很大的提高!
给几个测试数据~~
(a-(b-c))
((((a)-(a+b)-((a+b))-(a+b)+a)))
A-((B+C))
答案自己看就知道了!第二个数据很容易错的!
给几个测试数据~~
(a-(b-c))
((((a)-(a+b)-((a+b))-(a+b)+a)))
A-((B+C))
答案自己看就知道了!第二个数据很容易错的!
#include <iostream> #include <cstring> #include <cstdio> #include <stack> using namespace std; stack<bool> s; int main() { //freopen("a.txt","r",stdin); char ch[300],src[300],tch[300],aim[300]; int len,i,cnt1,cnt2,k,cas; bool flag; cin>>cas; getchar(); while(cas --) { cin.getline(ch,300); len = strlen(ch); k = 0; cnt1 = 0; cnt2 = 0; for(i = 0;i < len;i ++) { if(ch[i] !=' ') {src[k] = ch[i]; k++;} } len = k; k = 0; for(i = 0;i < len;i ++) { if(i>0&&src[i] == '('&&src[i-1] == '-') { tch[k++] = src[i]; flag = 1; s.push(flag); continue; } if((i>0&&src[i] == '('&&src[i-1] == '+')||(src[i] == '('&&src[i-1]=='(')||(src[i]=='('&&i==0) ) { flag = 0; s.push(flag); continue; } if(src[i] == ')') { if(!s.empty()) { flag = s.top(); s.pop(); if(flag == 1) {tch[k++] = ')';} } continue; } tch[k ++] = src[i]; } len = k; k = 0; for(i = 0;i < len;i ++) { if(tch[i] == '('&&tch[i+2] ==')') continue; if(tch[i] == ')'&&tch[i-2]=='(') continue; aim[k++] = tch[i]; } for(i = 0;i < k;i ++) cout<<aim[i]; cout<<endl; } return 0; }
相关文章推荐
- ZOJ 1423 (Your)((Term)((Project))) (POJ 1690)
- ZOJ-1423-(Your)((Term)((Project))) 【模拟】
- ZOJ 1423_(Your)((Term)((Project)))
- ZOJ 1423 (Your)((Term)((Project))) (POJ 1690) (模拟)
- ZOJ 1423 (Your)((Term)((Project))) (模拟+数据结构)
- TOJ 2196 ZOJ 1423 (Your)((Term)((Project))) 字符串处理
- zoj1423(Your)((Term)((Project))) (栈——基础练习)
- zoj 1423 (Your)((Term)((Project)))
- ZOJ 1423 POJ 1690 (Your)((Term)((Project)))
- ZOJ Problem Set - 3665 Yukari's Birthda
- ZOJ Problem Set - 3938 Defuse the Bomb
- ZOJ Problem Set - 1045 HangOver
- ZOJ Problem Set - 1045 & ZOJ Problem Set - 1048
- ZOJ Problem Set - 2965 Accurately Say "CocaCola"!
- ZOJ Problem Set - 1048 Financial Management
- ZOJ Problem Set - 1051 A New Growth Industry
- ZOJ Problem Set - 1337 Pi 最大公约数
- ZOJ Problem Set - 1049
- ZOJ Problem Set - 1649 - Rescue
- ZOJ Problem Set–1712 Skew Binary