HDOJ 1003题 代码写出,本机测式无问题,但WA,望指导
我在我的电脑上运行无错,但是一当我上OJ的时候,就出现WA,我也是醉了。找了半天没找不到错误。程序代码:
#include <stdio.h> int main() { int n1,n2, start, end, sum; int i, j, temp, tempsum, start_t; j = 0; tempsum = -1005; sum = -1005; scanf("%d", &n1); while (++j) { if(j > n1) break; scanf("%d", &n2); start_t = 1; end = 1; for(i=1; i<=n2; i++) { scanf("%d", &temp); tempsum += temp; if(tempsum > sum) { sum = tempsum; start = start_t; end = i; } if(tempsum < 0) { tempsum = 0; start_t = i+1; } } printf("Case %d:\n", j); printf("%d %d %d\n", sum, start, end); if(j < n1) printf("\n"); tempsum = sum = -1005; } return 0; }
[此贴子已经被作者于2016-2-8 18:40编辑过]