本站遷移

因為我最近租用了網路空間以及網域,
故本站已遷移至新網站~
這邊的資訊已經正在進行搬移的工作~
希望各位可以到新網站去逛XD

New Website:
http://knightzone.org/

搜尋此網誌

2011年3月14日 星期一

[UVa]11059:Maximum Product

直接Brute Force去尋找乘積最大的連續數字。

[C](0.012)
#include<stdio.h>
int main()
{
int N;
int M = 1;
while( scanf( "%d", &N ) != EOF )
{
long long S[20] = {0};
int i;
for( i = 0 ; i < N ; i++ )
scanf( "%lld", &S[i] );
long long P = 0, temp;
int j;
for( i = 0 ; i < N ; i++ )
{
temp = S[i];
P = ( temp > P ) ? temp : P;
for( j = i+1 ; j < N ; j++ )
{
temp *= S[j];
P = ( temp > P ) ? temp : P;
}
}
printf( "Case #%d: The maximum product is %lld.\n\n", M++, P );
}
return 0;
}
view raw UVa11059.c hosted with ❤ by GitHub

0 意見:

張貼留言