题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1003
#include <stdio.h> #include <string.h> #include <math.h> #define MAX 21 int a[MAX]; char c[MAX*2]; int main() { int n,i,j,k,index; int sum,x,y,maxNum,isnegative; int isfirst; int isfirblank; scanf("%d",&n); fflush(stdin); for(i=0;i<n;i++) { index=sum=x=y=0; isnegative = 1; isfirblank=isfirst=1; fgets(c,sizeof(c),stdin); for(j=0;j<strlen(c);j++){ if(c[j]>='0'&&c[j]<='9') { if(isfirst) a[index]*=10*isnegative; else a[index]*=10; a[index]+=(c[j]-'0')*isnegative; isfirst=0; isfirblank=1; }else if(c[j]=='-') { isnegative = -1; } else { if(isfirblank) index++; isfirblank=0; isnegative=1; isfirst=1; } } maxNum=a[0]; for(k=0;k<index;k++) { sum=a[k]; for(j=k+1;j<index;j++) { sum+=a[j]; if(sum>maxNum) { maxNum=sum; x=k; y=j; } } } printf("Case %d:\n%d %d %d\n",i+1,maxNum,x+1,y+1); if(i!=(n-1)) printf("\n"); fflush(stdin); for(j=0;j<strlen(c);j++) a[j]=0; } return 0; }
PS:这个也没得到ac,求高人指导