Pair development returns the sum of the largest sub-arrays in an integer array

Source: Internet
Author: User

First, title:

Returns the and of the largest sub-array in an integer array.

Second, requirements:

Enter an array of shapes 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. Requires a time complexity of O (n). 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).

Iii. Division of Labor

I chose the role of the Navigator, and the partner was the driver's responsibility;

Here is our job Photo:

Iv. Impressions

This pair development let me feel the Three Stooges the meaning of a Zhuge Liang and not what I always thought Three Stooges was just a bunch of smelly cobbler. Our programming ability is not very strong, but in our cooperation, often can complement each other, and quickly find the solution to the problem, clearer to find the wrong place. For example: The beginning of the project I was tangled in the requirements of the topic, not clear sub-array and what is going on, through our mutual discussion, let me not in the beginning of the process of the wrong, really lucky, wrong, it should be the credit of our cooperation. Later on how to implement the traversal of the sub-array and we discussed for a long time, first I say my idea, with a triple loop to find the various arrays and, but he said to ask O (n), ok I think simple. The result of the final discussion was to output an array of 5 elements, and then to compare each array. This is within our ability. In this small training, we find that pairing programming is really a more effective result, and can broaden the thinking, I like the first attempt of this programming method.

Five Code

#include <iostream.h>
int main ()
{
int a[1000];
int Max;

int sum[1000];
int i;
int n;
Int J;
cout<< "Number of input array members:";
cin>>n;
cout<< "Input 5-tuple array:";

for (i=0;i<5;i++)
{
cin>>a[i];

}

for (i=0;i<5;i++)
{
Sum[i]=a[i];
}
for (i=0;i<4;i++)
{
SUM[5+I]=A[I]+A[I+1];
}
for (i=0;i<3;i++)
{
SUM[9+I]=A[I]+A[I+1]+A[I+2];

}
for (i=0;i<2;i++)
{
SUM[12+I]=A[I]+A[I+1]+A[I+2]+A[I+3];
}
for (i=0;i<1;i++)
{
SUM[14+I]=A[I]+A[I+1]+A[I+2]+A[I+3]+A[I+4];
}

MAX=SUM[0];

for (i=0;i<15;i++)
{
if (Sum[i]>max)
{

Max=sum[i];
J=i;
}

}
cout<< "sub-array and maximum:" << "sum[" <<j<< "]=" <<max<<endl;

return 0;
}

Six. Results

Pair development returns the sum of the largest sub-arrays in an 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.