标签:
#include <iostream> #include <algorithm> #include <cstdio> using namespace std; int main() { int T; __int64 t; scanf("%d",&T); while(T--) { __int64 ans = 1; __int64 a[65]; int n; int q = 0,f = 0; scanf("%d",&n); for(int i = 1;i <= n;i++) { scanf("%I64d",&t); if(t > 0) ans *= t; else if(t == 0) f++; else a[++q] = t; } //把0会造成影响的两种特殊情况拿出来处理一下 if(q+f == n) { if(!q) { printf("0\n"); continue; } if(q == 1) { if(!f) {printf("%I64d\n",a[1]);continue;} if(f) {printf("0\n");continue;} } } //如果有正数存在 if(q%2 == 0) { for(int i = 1;i <= q;i++) ans *= a[i]; printf("%I64d\n",ans); continue; } else { sort(a+1,a+1+q); for(int i = 1;i <= q-1;i++) ans *= a[i]; printf("%I64d\n",ans); continue; } } ) return 0; }
标签:
原文地址:http://www.cnblogs.com/immortal-worm/p/4959269.html