Returns the number of the largest sub-arrays in a two-dimensional integer array

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.