maximum product

N | Maximum product

题目分析
1.遍历每一种情况大于max就替换
2.注意行末回车,否则会PE
3.EOF(end of file)按ctrl+z退出

代码

#include<iostream>
#include<stdio.h>
#include<math.h>
#include<string>
using namespace std;
int main()
{
	int t, n, k = 0;
	long long pro = 1, flag, max;
	int a[101];
	while (scanf("%d", &n) != EOF)
	{
		flag = 0;
		max = 0;
		pro = 1;
		k++;
		for (int i = 0; i < n; i++)
			cin >> a[i];
		for (int i = 0; i < n; i++)
		{
			pro = 1;
			for (int j = i; j < n; j++)
			{
				pro = pro * a[j];
				if (pro > max)
					max = pro;
			}
		}
		if (max > 0)
			cout << "Case" << " " << "#" << k << ":" << " " << "The maximum product is " << max << "." << endl;
		else
			cout << "Case" << " " << "#" << k << ":" << " " << "The maximum product is " << 0 << "." << endl;
		cout << endl;
	}
	return 0;
}
posted @ 2022-01-23 16:03  Lewis_1231  阅读(45)  评论(0)    收藏  举报