zoukankan      html  css  js  c++  java
  • UVa 11059 最大乘积

    https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2000

    题意:找出乘积最大的连续子序列。

    思路:这道题目我挺无语的,一直超时,也不知道是哪里出了问题,反正最后试来试去终于有种办法成功了。不过好像这道题目不需要考虑输出0的情况吧。

     1 #include<iostream>
     2 using namespace std;
     3 
     4 int main()
     5 {
     6     int ans[20];
     7     int n;
     8     int kase = 0;
     9     while (cin>>n)
    10     {
    11         kase++;
    12         for (int i = 0; i < n; i++)
    13             cin >> ans[i];
    14         long long max = 0;
    15         long long sum;
    16         for (int i = 0; i < n; i++)
    17         {
    18             sum = 1;
    19             for (int j = i; j < n; j++)
    20             {
    21                 sum *= ans[j];
    22                 if (sum>max)  max = sum;
    23             }
    24         }
    25         cout << "Case #" << kase << ": The maximum product is " << max << ".
    
    ";
    26     }
    27     return 0;
    28 }
  • 相关阅读:
    购物网站被p.egou.com强制恶意劫持
    css下拉菜单
    StringToInt
    JframeMaxSize
    frameMaxSize
    inputChar
    英语要求
    sciAndSubject
    fileRename
    tensorflowOnWindows
  • 原文地址:https://www.cnblogs.com/zyb993963526/p/6287790.html
Copyright © 2011-2022 走看看