1、题目名称

Maximum Product

2、题目地址

https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2000

3、题目内容

Given a sequence of integers S = {S1, S2, . . . , Sn}, you should determine what is the value of the maximum positive product involving consecutive terms of S. If you cannot find a positive sequence, you should consider 0 as the value of the maximum product.

Input

Each test case starts with 1 ≤ N ≤ 18, the number of elements in a sequence. Each element Si is an integer such that −10 ≤ Si ≤ 10. Next line will have N integers, representing the value of each element in the sequence. There is a blank line after each test case. The input is terminated by end of file (EOF).

Output

For each test case you must print the message: ‘Case #M: The maximum product is P.’, where M is the number of the test case, starting from 1, and P is the value of the maximum product. After each test case you must print a blank line.

Sample Input

3

2 4 -3

5

2 5 -1 2 -1

Sample Output

Case #1: The maximum product is 8.

Case #2: The maximum product is 20.

大致意思就是,给出一个序列,问这个序列中最大连续累乘的子序列中,最大的值为多少,如果都为负数,则输出0.

感受:  一定要记得用long long , 还有格式问题,否则可能pe

 #include"iostream"
using namespace std;
int a[];
int main(){
int n,out;
out=;
while(cin>>n){
for(int i=;i<n;i++)
cin>>a[i];
long long max=;
for(int i=;i<n;i++)
for(int j=i;j<n;j++){
long long z=;
for(int q=i;q<=j;q++)
z=z*a[q];
if(max<z) max=z;
}
cout<<"Case #"<<++out<<": The maximum product is "<<max<<"."<<endl<<endl; }
}

最新文章

  1. writing
  2. svn忽略某个文件提交
  3. jquery动态改变div宽度和高度
  4. 【原创&#183;总结】影响sql查询性能的因素
  5. 用python简单处理图片(4):图像中的像素访问
  6. Docker-数据卷和数据容器卷
  7. ubuntu14.04建立交叉编译环境, 注意事项
  8. QT 多线程程序设计【转】
  9. How to detect and avoid memory and resources leaks in .NET applications
  10. [转] 详细整理:UITableView优化技巧
  11. Subarray Sum Closest
  12. mysql-5.7.10-winx64 MySQL服务无法启动,服务没有报告任何错误的解决办法
  13. EL表达式学习
  14. 201521123072《java程序设计》第五周学习总结
  15. Git随笔 -- 初始化远程仓库
  16. [LeetCode] Majority Element 求大多数
  17. JavaScript权威指南--脚本化文档
  18. tornado-模板继承extend,函数和类的导入
  19. Hbase Scan的重要参数
  20. PowerDesigner15.1使用技巧总结

热门文章

  1. C语言基础知识【作用域规则】
  2. sublime中如何安装vue.js插件,并使代码高亮显示
  3. Mysql的学习研究
  4. 解决ubuntu中文乱码问题
  5. Myeclipse 文件注释和解注释
  6. 【BZOJ3991】[SDOI2015]寻宝游戏 树链的并+set
  7. EasyPlayer RTSP播放器OCX RegSvr32注册报错,DllRegisterServer调用失败,错误代码为0x80040200 解决方法
  8. c# 怎么更改DataTable 中某列的值?
  9. OSI模型第三层网络层-初识路由协议
  10. [Delphi]解决Delphi Distiller运行报错&quot;HKEY_CURRENT_USER\\&quot; is of wrong kind or size