zoukankan
html css js c++ java
HDU3350 #define is unsafe 栈的应用
//数据结构-栈的应用 #include<iostream> #include<string> #include<vector> using namespace std; struct node { int value;//值 int add;//+的次数 }; //用容器实现栈的FILO vector<node> ans;//数值栈 vector<char> sig;//符号栈 int main() { int t, i; string str; node temp, temp2; cin>>t; while(t--) { cin>>str; temp.value = 0; temp.add = 0; sig.clear(); ans.clear(); for(i = 0; i < str.length(); i++) { //逐字打扫,只有'('、'+'、 ','、')'和数字是有用的,"MAX"不用处理 //优先级:'(' > '+' > ',' > ')' switch (str[i]) { case '(': sig.push_back(str[i]); temp.value = 0; temp.add = 0; break; case '+': ans.push_back(temp); sig.push_back(str[i]); temp.value = 0; temp.add = 0; break; case ',': while(!sig.empty() && sig.back() == '+') { temp2 = ans.back(); temp.value = temp.value + temp2.value; temp.add = temp.add + 1 + temp2.add; ans.pop_back(); sig.pop_back(); } ans.push_back(temp); sig.push_back(str[i]); temp.value = 0; temp.add = 0; break; case ')': while(!sig.empty() && sig.back() == '+') { temp2 = ans.back(); temp.value = temp.value + temp2.value; temp.add = temp.add + 1 + temp2.add; ans.pop_back(); sig.pop_back(); } temp2 = ans.back(); if(temp2.value > temp.value) { temp.value = temp2.value; temp.add = temp2.add * 2 + temp.add; } else { temp.add = temp.add * 2 + temp2.add; } sig.pop_back();sig.pop_back(); ans.pop_back(); break; case '0':case '1':case '2':case '3':case '4':case '5':case '6':case '7':case '8':case '9': temp.value = temp.value * 10 + str[i] - '0'; break; } } while(!sig.empty() && sig.back() == '+') { temp2 = ans.back(); temp.value = temp.value + temp2.value; temp.add = temp.add + 1 + temp2.add; ans.pop_back(); sig.pop_back(); } cout<<temp.value<<' '<<temp.add<<endl; } return 0; }
查看全文
相关阅读:
Codefores 506A Mr. Kitayuta, the Treasure Hunter( DP && dfs )
Goals ? Ideals ?
HDU 5159 Card( 计数 期望 )
HDU 1387 Team Queue( 单向链表 )
HDU 1709 The Balance( DP )
HDU 2152 Fruit( DP )
HDU 1398 Square Coins(DP)
HDU 5155 Harry And Magic Box( DP )
HDU 3571 N-dimensional Sphere( 高斯消元+ 同余 )
最大连续自序列
原文地址:https://www.cnblogs.com/windmissing/p/2559882.html
最新文章
自定义组件出现实例化失败
ListView滑动监听和设置点击事件
ListView移动和动态添加数据
ViewHolder优化ListView
自定义view实现topbar
自定义textview产生渐变色
GestureDetector检测手势
VelocityTracker检测手指的移动速度
Fast rcnn,Faster rcnn(RCNN改进)
hdu 6085 Rikka with Candies (set计数)
热门文章
hdu 6092 Rikka with Subset (集合计数,01背包)
hdu 4609 3-idiots(FFT+去重处理)
hdu 1402 A * B Problem Plus (FFT模板)
FFT模板
BZOJ 2301 莫比乌斯反演入门
Codeforces Round #420 (Div. 2) E. Okabe and El Psy Kongroo dp+矩阵快速幂
POJ 2299 Ultra-QuickSort (树状数组+离散化 求逆序数)
hdu 5860 Death Sequence(递推+脑洞)
Codeforces 789e The Great Mixing (bitset dp 数学)
Codefores 507B Amr and Pins
Copyright © 2011-2022 走看看