An array of the largest subarray and

Source: Internet
Author: User

Title: Expands on an existing array to find the sum of the largest sub-arrays of the end-to-end connections:

Requirements: Enter a one-dimensional shape array with positive and negative numbers in the array.

One or more consecutive integers in an array make up a sub-array, each of which has a and.

The maximum value for the and of all sub-arrays.

Pair programming Requirements: 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).

Pair development process:

This time the programming is based on the last thought of the array, I and my partner Angel LR Demon began a serious discussion, and then combined with class discussion, how can be in a one-dimensional array on the basis of the original, coupled with the end-to-end condition, while reducing the complexity of time, The approximate idea of this method is: Iterate through the array of each number of the first number into the last number, the specific algorithm a[i-1]=a[i], this becomes a new one-dimensional array, output the maximum number of sub-arrays per array, and then compare each output and, find the largest:

Source:

#include <iostream.h> int maxsum (int* A, int n)//defines a method {int sum=0 that is the largest subarray of a one-dimensional array;          int b=0;         for (int i=0; i<n; i++) {if (b<0) b=a[i];         else B+=a[i];     if (sum<b) sum=b; } return sum;    } int main () {int n,temp,b;    int sum=0;    int i;    int a1,a2;    cout<< "Please enter the number of elements in the array:" <<endl;    cin>>n;    cout<< "Please enter the elements of the array:" <<endl;         int *a=new Int[n];    for (i=0;i<n;i++) {cin>>a[i];}    cout<< "The maximum number of sub-arrays in this end-to-end array is possible with the following:" <<endl;    cout<< "1th arrangement:" <<endl;    for (i=0;i<n;i++) {cout<<a[i]<< "";}    cout<< "Maximum sub-array and as:" <<maxsum (a,n) <<endl;    A1=maxsum (A,n);    for (b=1;b<n;b++) {temp=a[0];                  for (i=1;i<=n;i++) {a[i-1]=a[i];       } a[n-1]=temp;       cout<< "<<b+1<<" type of Arrangement: "<<endl; for (i=0;i<n;i++) {cout<<a[i]<< "";}       cout<< "Maximum sub-array and as:" <<maxsum (a,n) <<endl;    if (Maxsum (a,n) >=sum) {sum=maxsum (a,n);}      } a2=sum;      cout<<endl;      if (A1&GT;=A2) {cout<< "In the sum, the largest subarray and is:" &LT;&LT;A1&LT;&LT;ENDL;}         Else {cout<< "On top, the largest sub-array and is:" &LT;&LT;A2&LT;&LT;ENDL;} return 0; }

  

Feelings:

Cooperation is called cooperation because it is a matter of two or more people. In an array of exercises today, my teammates and I discussed this topic so that we could have a clearer understanding of the problem and let the programming be handy.

Cooperation:

An array of the largest subarray 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.