zoukankan      html  css  js  c++  java
  • 第七章部分例题最大乘积

    思路:用数组存储

    然后枚举起点和终点来创建子序列由于乘积很大所以要用long long 同时使用cout输出避免printf不同编译器的不同实现

     1 #include <cstdio>
     2 #include <algorithm>
     3 #include <iostream>
     4 
     5 using namespace std;
     6 
     7 long long const inf=-1e18;
     8 int s[20];
     9 
    10 int main()
    11 {
    12     long long mu;
    13     long long best=inf;
    14 
    15     cout<<best<<endl;
    16 
    17     int n;
    18     cin>>n;
    19 
    20     for(int i=0;i<n;i++)
    21         scanf("%d",&s[i]);
    22 
    23     for(int i=0;i<n;i++)
    24         for(int j=n-1;j>=i;j--)
    25         {
    26             mu=1;
    27 
    28             for(int b=i;b<=j;b++)
    29                 mu*=s[b];
    30 
    31             best=max(best,mu);
    32         }
    33 
    34     cout<<best<<endl;
    35 }
    Yosoro
  • 相关阅读:
    python
    VSCompile
    Oracle学习
    CMD
    JQuery 学习
    单词
    解决Manjaro+win双系统相差8小时
    编辑器使用
    软件安装
    磁盘分区与逻辑卷管理
  • 原文地址:https://www.cnblogs.com/tclan126/p/7403637.html
Copyright © 2011-2022 走看看