UVa 11059
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2000因为n比较小,所以可以直接暴力。但我还是wa几次,因为少了换行,还是Cf好啊。
代码:
#include<iostream> #include<cstdio> #include<cstring> using namespace std; int main() { int n,a[20],ce=1; long long ans; while(scanf("%d",&n)!=EOF&&n!=0) { long long maxn=0; for(int i=1;i<=n;i++) scanf("%d",&a[i]); for(int i=1;i<=n;i++) { for(int j=i;j<=n;j++) { ans=1; for(int k=i;k<=j;k++) { ans*=(long long)a[k]; } maxn=max(maxn,ans); } } printf("Case #%d: The maximum product is %lld.\n\n",ce++,maxn); } return 0; }