NYOJ_44_子串和
#include<iostream> #include<cstdio> #include<algorithm> #include<cmath> #include<iostream> #include<cstdio> #include<algorithm> #include<cmath> #include<cstring> #include<string> using namespace std; int main() { int t,n,i,a,sum,Max; scanf("%d",&t); while(t--) { scanf("%d",&n); sum=-105;//题目说了最小整数为-100 Max=-105; for(i=0;i<n;++i) { scanf("%d",&a); if(sum<0) sum=a; //如果前面的数已经小于0了,重新记录sum else sum+=a; Max=sum>Max?sum:Max; } printf("%d\n",Max); } return 0; }