First , the title requirement: Returns the largest subarray in an integer array and input an array of shapes, with positive numbers in the array and negative values. One or more consecutive integers in an array make up an array, and each sub-array has one and. Second, the design idea: first enter a string of arrays, define Max as the maximum value, define sum as the sum of the results; start from the beginning by adding the first and sum of the array to sum, judging the positive and negative of a[i], and judging the size of Max and sum for positive numbers, and if the sum is 0 for negative numbers If the final result is Max 0, then the array will be negative, just find the largest negative number. Outputs the sum of the largest sub-arrays. Third, Code://Lulinlain Yuhuihui 2016.3.26#include<iostream>using namespacestd;intMain () {inta[ -],n;intsum=0, max=0; cout<<"Please input the number of the array:"; Cin>>N;cout<<"Please input"<<N<<"Number :"; for(intI=0; i<n;i++) Cin>>A[i]; for(intI=0; i<n;i++) {sum+=a[i];//assign each sum to sum if(a[i]>=0) { if(max<sum) {Max=sum; } } if(sum<0) {sum=0; }}if(max==0) {Max=a[0]; for(intI=1; i<n;i++) { if(a[i]>max) Max=A[i]; }}cout<<"The max is:"<<max<<Endl;return 0;} Four, Time: The plan took 4 hours, the actual cost of 7 hours; including debugging procedures and the design of the Zhao program; five, experience: This experiment compared to the previous experiments is relatively simple, as long as the design of the idea of programming to achieve it is relatively easy.
Find the sum of the largest array of words in the first part