First, the topic requirements
Title: Returns the number of the largest sub-arrays in a two-dimensional integer array.
Requirements: Enter a two-dimensional shape array with positive and negative numbers in the array.
A two-dimensional array is connected to the end of the line, like a belt.
One or more consecutive integers in an array make up a sub-array, each of which has a and. To find the maximum of all sub-arrays
The pair completes the programming task. One person is mainly responsible for program analysis, code programming. One person is responsible for code review and Code test plan.
Publish a blog post about the process, experience, and how to resolve conflicts between two people (attach a work photo of the development). (As of Thursday April 21 24:00)
Second, design ideas
The design of this experiment is very simple, that is, the idea of merging the previous two experiments, a line of ring array into a few lines of ring array to calculate.
Third, the Code
//Connor, April 17, 2015#include <iostream>#include<time.h>using namespacestd;#defineN 3voidMain () {Srand (int) Time (0)); intI,j,a[n][n]; for(i=0; i<n;i++) for(j=0; j<n;j++) {A[i][j]=-rand ()% $+ -; } cout<<"The resulting random matrix is as follows:"<<Endl; for(i=0; i<n;i++) { for(j=0; j<n;j++) {cout<<a[i][j]<<'\ t'; } cout<<Endl; } intC=0-B: -],m,sum,sum1; for(i=0;i< -; i++) B[i]=0; for(i=0; i<n;i++) { for(intf=0; f<n;f++) {m=F; Sum=0; Sum1=0; for(j=m;j<n;j++) {sum+=A[i][j]; B[C]=sum; C++; Sum1=sum; for(intd=i+1;d <n;d++) { for(inte=f;e<=j;e++) {sum1+=A[d][e]; } B[c]=sum1; C++; } } if(m>n-1) {m=0; } } } for(i=0; i<c;i++) cout<<b[i]<<" "; cout<<Endl; intMax; Max=b[0]; for(i=0; i<c;i++) { if(b[i]>max) {Max=B[i]; }} cout<<Max;}
Four, the Operation effect
V. Summary
The combination of the two programs can create a new program, and later in other programming experiments can use their own previously written procedures and improve. This method is quick and convenient.
Returns the number of the largest sub-arrays in a two-dimensional integer array