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.

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
int main()
{
int n,t=,a[],i,j;
long long maxn,sum;
while(cin >> n)
{
memset(a,,sizeof(a));
for(i=;i<n;i++)
cin >> a[i];
for(i=,maxn=;i<n;i++)
{
for(j=i,sum=;j<n;j++)
{
sum *= a[j];//直接枚举起点到每个可能的终点的乘积
if(sum>maxn)
maxn = sum;
}
}
cout << "Case #" << t++ << ": The maximum product is " << maxn << "." << endl;
cout << endl;
}
return ;
}

最新文章

  1. mysql 数据库引擎
  2. codevs 3288 积木大赛
  3. column &#39;id&#39; in field list is ambiguous
  4. Linux的后台执行进程之nohup
  5. ftp 建立、配置、实用软件 fileZilla server
  6. 汇编语言-求X的阶乘
  7. 转--Server “**” has shut down the connection prematurely一例分析
  8. $().text() 和 $().html()
  9. 【HDU 2063】过山车(二分图最大匹配模板题)
  10. [POI 2007]ZAP-Queries
  11. FFmpeg的HEVC解码器源代码简单分析:环路滤波(Loop Filter)
  12. android studio——替换全局的某个字符串
  13. C和C++头文件大全
  14. 20165234 2017-2018-2《Java程序设计》课程总结
  15. 2017-2018 ACM-ICPC Southeast Regional Contest (Div. 1)
  16. Intel CPU 漏洞分析
  17. [转]zookeeper集群 initLimit和syncLimit
  18. mongodb 字符串查找匹配中$regex的用法
  19. Jquery autocomplete.js输入框联想补全功能
  20. c#版本与vs的对应关系

热门文章

  1. 【JDK】JDK源码分析-ReentrantLock
  2. win7 python pdf2image入坑经历
  3. mac安装ElasticSearch+head+node+一个例子~
  4. Docker最简单入门之(一)——介绍和配置Docker
  5. 有趣的RPC理解
  6. C语言数组排序——冒泡排序、选择排序、插入排序
  7. python第二课--分支结构与循环结构
  8. Node.js爬虫实战 - 爬你喜欢的
  9. java之异常详解
  10. 域名、主机名、网站名以及 URL 基础概念