Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u

Description

Vanya is doing his maths homework. He has an expression of form , where x1, x2, ..., xn are digits from 1 to 9, and sign represents either a plus '+' or the multiplication sign '*'. Vanya needs to add one pair of brackets in this expression so that to maximize the value of the resulting expression.

Input

The first line contains expression s (1 ≤ |s| ≤ 5001, |s| is odd), its odd positions only contain digits from 1 to 9, and even positions only contain signs  +  and  * .

The number of signs  *  doesn't exceed 15.

Output

In the first line print the maximum possible value of an expression.

Sample Input

Input
3+5*7+8*4
Output
303
Input
2+3*5
Output
25
Input
3*4*5
Output
60

Hint

Note to the first sample test. 3 + 5 * (7 + 8) * 4 = 303.

Note to the second sample test. (2 + 3) * 5 = 25.

Note to the third sample test. (3 * 4) * 5 = 60 (also many other variants are valid, for instance, (3) * 4 * 5 = 60).

Source

 
解题:暴力瞎搞,注意int溢出,傻逼逼的把栈写成int了。。。哎吸取教训
 
 #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
vector<int>pos;
stack<LL>num;
stack<char>op;
LL calc(const string &str) {
while(!num.empty()) num.pop();
while(!op.empty()) op.pop();
for(int i = ,slen = str.length(); i < slen; ++i) {
if(str[i] == ')') {
while(op.top() != '(') {
LL tmp = num.top();
num.pop();
if(op.top() == '*') num.top() *= tmp;
else if(op.top() == '+') num.top() += tmp;
op.pop();
}
op.pop();
continue;
}
if(isdigit(str[i])) num.push(str[i] - '');
else if(str[i] == '+' && !op.empty() && op.top() == '*') {
while(!op.empty() && op.top() == '*') {
LL tmp = num.top();
num.pop();
num.top() *= tmp;
op.pop();
}
op.push(str[i]);
} else op.push(str[i]);
}
while(!op.empty()) {
LL tmp = num.top();
num.pop();
if(op.top() == '*') num.top() *= tmp;
else if(op.top() == '+') num.top() += tmp;
op.pop();
}
return num.top();
}
int main() {
string str;
cin>>str;
pos.push_back(-);
int slen = str.length();
for(int i = ; i < slen; i += )
if(str[i] == '*') pos.push_back(i);
pos.push_back(slen);
slen = pos.size();
LL ret = INT_MIN;
for(int i = ; i+ < slen; ++i)
for(int j = i+; j < slen; ++j) {
string s = str;
s.insert(pos[i]+,,'(');
s.insert(pos[j]+,,')');
ret = max(ret,calc(s));
}
cout<<ret<<endl;
return ;
}

最新文章

  1. 好用的Markdown编辑器一览 readme.md 编辑查看
  2. [异常解决] ubuntukylin16.04 LTS中关于flash安装和使用不了的问题解决
  3. IntelliJ IDEA安装及jsp开发环境搭建
  4. Spring + SpringMVC + Druid + JPA(Hibernate impl) 给你一个稳妥的后端解决方案
  5. 【.NET】Cookie操作类
  6. BZOJ 2342: [Shoi2011]双倍回文
  7. 20151009 C# 第一篇 程序编写规范
  8. POJ 3685
  9. 初识 Lucene
  10. HTML5学习笔记简明版 目录索引
  11. jquery hover延时
  12. Servlet过滤器——过滤器分析流量
  13. 【转载】GDI 映像方式 之 SetViewportOrgEx 与 SetWindowOrgEx 解析
  14. 使用LRU算法缓存图片,android 3.0
  15. jquery实现照片墙
  16. DW1000 用户手册中文版 第5章 媒体访问控制(帧过滤)
  17. Hive管理表分区的创建,数据导入,分区的删除操作
  18. 导航菜单点击图片切换--jquery
  19. 第九周助教工作总结——NWNU李泓毅
  20. elasticsearch6.7 05. Document APIs(3)GET API

热门文章

  1. BZOJ 4942 NOI2017 整数 (压位+线段树)
  2. tyvj1864 [Poetize I]守卫者的挑战
  3. TI低功耗蓝牙(BLE)介绍
  4. JavaScript实现html页面转换成图片格式
  5. idea 编辑器 光标问题!(insert键)
  6. 洛谷 P2949 [USACO09OPEN]工作调度Work Scheduling
  7. [using_microsoft_infopath_2010]Chapter1 介绍InfoPath2010
  8. 【中山市选2010】【BZOJ2467】生成树
  9. nginx源代码分析--从源代码看nginx框架总结
  10. perl getopt 用法