Outputs the largest sub-array in a two-dimensional ring array and

Source: Internet
Author: User

Crew Shi Li Haisu

First, the topic

Outputs the largest sub-array in a two-dimensional ring array and

Second, the design idea

Combining the method of solving one-dimensional annular array and ordinary two-dimensional array, the street is a method to solve the two-dimensional annular array.

Third, the source code

#include <iostream.h>#include<time.h>#include<stdlib.h>intQiumax (intArry[],intmax) {    inti; Longsum;  for(i=0;i<5; i++)    {         for(i=0;i<5; i++) {Arry[i+5]=Arry[i]; }    }     for(intj=0;j<5; j + +) {sum=0;  for(intk=j;k<5+j;k++) {sum=sum+Arry[k]; if(sum>max) {Max=sum; }        }    }    returnMax;}intMain () {intQiumax (intarry[Ten],intmax); inti,j,k; intarry[5][Ten]={{1,1,1,-1,-1},{1,1,1,-1,-1},{1,1,1,-1,-1},{1,1,1,-1,-1},{1,1,1,-1,-1}}; intarry1[Ten]={0,0,0,0,0,0,0,0,0,0}; intmax=arry[0][0];  for(i=0;i<5; i++)    {         for(j=0;j<5; j + +) {arry[i][j+5]=Arry[i][j]; }    }     for(i=0;i<5; i++)    {         for(j=i;j<5; j + +)        {             for(k=0;k<5; k++) {Arry1[k]+=Arry[j][k]; } Max=Qiumax (Arry1,max); }         for(k=0;k<Ten; k++) {Arry1[k]=0; }} cout<<"MAX is"<<" "<<max<<Endl; return 0;}

Iv. Results

Five, experimental experience

This experiment is not very difficult, just to combine the first two ideas, modify the next two programs can be.

But in the invocation of the function of the argument is that we have a problem, corrected after the transfer of a deeper understanding of the parameters.

Outputs the largest sub-array in a two-dimensional ring array and

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.