Crew Shi Li Haisu
First, the topic
Output an array of the most large subarray, the array is the Int32 type, there are 1000 numbers, to ensure that the maximum number of sub-arrays and not overflow.
Second, the design idea
Randomly generates an array of 1000 numbers, seeking the maximum number of sub-arrays and the process of judging if overflow, if overflow, the output overflows.
Third, the source code
#include <iostream.h>LongMAX (unsignedLongArry[],intlength) {unsignedLongsum=arry[0]; unsignedLongmaxsum=arry[0]; for(intI=1; i<length;i++) { if(sum<0) {sum=Arry[i]; } Else{sum=sum+Arry[i]; if(sum<Long_max) {cout<<"Overflow"<<Endl; Break; } } if(maxsum<=sum) {Maxsum=sum; } } returnmaxsum;}intMain () {unsignedLonga[ +]; for(intI=0;i< +; i++) {A[i]= (unsignedLong) rand ()%5+4294967290; cout<<a[i]<<" "; } unsignedLongQ=max (A, +); cout<<Endl; cout<<Q; if(q<0) {cout<<"Overflow"<<Endl; } return 0;}
Iv. Results
Five, experimental experience
We discussed for a long time, did not think of how to deal with overflow, and finally only output results overflow.
The other process is not much difficult, but the previous procedures have made some improvements, and hope to continue to progress in the future.
Vi. Photos
Outputs the largest and most large subarray in an array and does not overflow