例题7-2 最大乘积 UVa 11059
2015-08-22 18:56
302 查看
输入n个元素的序列s,找出一个连续序列的最大乘积
分析:数据较小,直接O(n^2)可得出,用 long long
注意:printf输出 long long 时要用%lld ,好像LINUX系统的原因,win系统要用%I64d ,因为我一直用%I64d WA好多次
分析:数据较小,直接O(n^2)可得出,用 long long
注意:printf输出 long long 时要用%lld ,好像LINUX系统的原因,win系统要用%I64d ,因为我一直用%I64d WA好多次
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; #define LL long long int main() { int N,s[20]; int p=0,flag=1; while(scanf("%d",&N)!=EOF){ for(int i=0;i<N;i++) scanf("%d",&s[i]); LL maxn=0; for(int i=0;i<N;i++){ LL temp=1; for(int j=i;j<N;j++){ temp*=s[j]; if(temp>maxn) maxn=temp; } } if(maxn<0)maxn=0; // printf("Case #%d: The maximum product is %lld.\n\n",flag++,maxn); printf("Case #%d: The maximum product is %I64d.\n\n",flag++,maxn); } return 0; }
相关文章推荐
- 杂感
- 【CF 450A】 Jzzhu and Children
- 黑马程序员_集合-Map
- CString + UINT Error:有多个运算符"+="与这些操作数匹配
- 这些年的工作的学习笔记
- 08.实例方法和类方法的区别与及工厂方法
- dsgfdgdf
- linux问题总结
- 黑马程序员_集合-set实现类
- Web前端面试题
- 14 Longest Common Prefix
- android-反编译后重新打包apk文件
- linux命令
- Binary Tree Paths
- asp.net MVC helper 和自定义函数@functions小结
- Go语言的RPC介绍(含Protobuf-RPC)
- lua基金会【五岁以下儿童】I/O文件操作
- mac基础终端命令入门
- 学习计划
- Android驱动之 Linux Input子系统之TP——A/B(Slot)协议