I. Title:
Returns the and of the largest sub-array in an integer array.
Requirements:
1. Enter an array of shapes with positive and negative numbers in the array.
2. One or more integers in the array make up a sub-array, each of which has a and.
3. Ask for the maximum value of all sub-arrays. Requires a time complexity of O (n).
Two. Design ideas.
Place the received array into a[i], place all the sub-arrays in the received array into b[i], and then find the maximum Max, which is the largest subarray of the array and.
Place the maximum foot mark in S[i] to find the first digit of the largest sub-array, S[i], and the number of consecutive added numbers T[i].
Three. Code.
#include <iostream.h>#defineMAX 10000intMain () {intk,t[max],o=0, d=0; intn=0, m=0; intB[max],a[max]; intS[max]; cout<<"Please enter the number of integers in the array:"<<Endl; CIN>>K; for(intI=0; i<k;i++) {cin>>A[i]; } for(intL=1; l<k+1; l++) { for(i=0; i<k-l+1; i++) { for(intj=i;j<i+l;j++) { if(j>k-1) { Break; } Elsem=m+A[j]; } B[n]=m; M=0; N=n+1; } } intmax=b[0]; for(i=1; i<n;i++) { if(max<B[i]) Max=B[i]; } for(i=0; i<n;i++) { if(max==B[i]) {S[d]=i+1; D++; } } intR=K; for(i=0; i<d;i++) {T[i]=0; for(intj=0; j<k;j++) { if(s[i]>=r&&r>=0) {S[i]=s[i]-R; T[i]=t[i]+1; R=r-1; } if(s[i]==0&&r>0&&j!=k-1) {S[i]=s[i]+r+1; Break; } if(s[i]==0&&r==0&&t[i]==k) {S[i]=s[i]+1; Break; }} R=K; } cout<<"The number of the largest sub-arrays in the array is:"<<max<<Endl; cout<<"such sub-arrays have altogether"<<d<<"Group"<<Endl; for(i=0; i<d;i++) {S[i]=s[i]-1; } for(i=0; i<d;i++) { if(d==1) cout<<"the sub-array is:"; Elsecout<<"Section"<<i+1<<"the group sub-arrays are:"; if(t[i]==0) {T[i]=1; } for(intj=s[i];j<s[i]+t[i];j++) {cout<<a[j]<<" "; } cout<<Endl; } return 0; }
Four. Run the results.
Five. Experience.
Pair development can make the team have more design ideas, can expand each person's ideas, to find a more simple algorithm, there are problems when two people can discuss with each other, better solve the problem.
When a person is programmed, another person can find some problems better from the perspective of the beholder. Avoid problems with your programming and find out why.
The best aspect of pairing development is making the program more optimized.
Six. Work photos.
Pair development The maximum sub-array of any one array