#UVa:11059-Maximum Product

直接硬爆解即可得解。

C++(0.024)

/*******************************************************/
/* UVa 11059 Maximum Product                           */
/* Author: LanyiKnight [at] knightzone.org             */
/* Version: 2012/09/15                                 */
/*******************************************************/
#include<iostream>
#include<cstdio>
using namespace std;

int main(){
  int N, casenum = 1;
  long long S[20], maxproduct, temp;

  while( scanf( "%d", &N ) != EOF ){
    for( int i = 0; i < N ; i++ )
      scanf( "%lld", &S[i] );

    maxproduct = 0;
    for( int i = 0 ; i < N ; i++ ){
      temp = 1;
      for( int j = i ; j < N ; j++ ){
        temp *= S[j];
        if( temp > maxproduct ) maxproduct = temp;
      }
    }
    printf( "Case #%d: The maximum product is %lld.\n\n", casenum++, maxproduct );

  }
  return 0;
} 

沒有迴響

本文還沒有迴響,快來搶頭香!

發表迴響