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; }
查看全文
相关阅读:
DM逻辑结构
DM常见问题
DM进程与线程
DM物理存储结构
systemdlogind.service的RemoveIPC参数影响
DM内存结构
DMSQL记录日志跟踪功能
ACM中java的使用
Java读取CSV文件为List
Vue打包优化 优化JS过大 西门
原文地址:https://www.cnblogs.com/windmissing/p/2559882.html
最新文章
Python del、pop()、remove()、clear()
Python fromkeys()
Python super() 多继承
Python __dict__
Python 访问闭包中的变量
Python lambda 细讲
Python 默认值参数
Python __repr__()
Python eval()、exac()
Python 浮点型精度问题
热门文章
Python有序列表插入元素(入门级代码)
用python爬虫爬取壁纸图片(入门级代码)
杨辉三角实现(python)
使用列表实现筛选法求素数(利用python的内置函数,快速求素数)
python求素数: [p for p in range(2, maxNumber) if 0 not in [p%d for d in range(2, int(p**0.5)+1)]]
2021/1/28 寻找数组的中心索引 收获:一颗星
【k8s权威指南】第三章 k8s核心原理
剑指offer斐波那契数列
剑指offer在二维数组中查找
DM定位慢SQL
Copyright © 2011-2022 走看看