Pair Development 5

Source: Internet
Author: User

Title:Returns the and of the largest subarray in a two-dimensional integer array. Requirements:Enter a two-dimensional shaping array with positive numbers in the array and a negative number. 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.

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).

First, design ideas

This time, we for each other better exercise, I and junk classmate Exchange position, by junk classmate responsible for program analysis, code programming, I am responsible for code review and Code test plan. Our idea is to extend the original two-dimensional array, the end-to-end splicing, assuming that the original two-dimensional array length and height are N and m, that is, to expand into 2n-1,2m-1, you must add a restriction, so that the number of rows and columns should not exceed the original N and M.

Second, the source code

#include <stdio.h>
int rect[55][55];//Two-dimensional array rows and columns up to a maximum of 55
int w,l; W indicates row, l indicates column
int longest (int a[])
{
int I,j,find=0,max;
for (i=0;i<l;i++)
{
max=0;
For (j=i;j<2*l-2&& (j-i) <l;j++)//Extend the length of the two-dimensional array to 2n-2
{
MAX+=A[J%L]; Rows and columns do not add up to the original maximum row and column values
if (Max>find)
Find=max; Find Gets the maximum value
}
}
return find;
}
int Rect (int a[55][55])
{
int i,j,k;
int find=0; Represents the final maximum value
int b[55];
int buf;
for (i=0;i<w;i++)
{
for (j=0;j<l;j++)
b[j]=0;
For (j=i;j<2*w-2&& (j-i) <w;j++)//Extend the length of the two-dimensional array to 2n-2
{
for (k=0; k<l; k++)
{
B[K]+=A[J%W][K]; Rows and columns do not add up to the original maximum row and column values
}
Buf=longest (b);
if (FIND&LT;BUF)
Find=buf;
}
}
return find;
}
int main ()
{
int i,j;
int result;
printf ("Please enter the rows and columns of the two-dimensional array: \ n");
scanf ("%d%d", &w,&l);
printf ("Please enter a two-dimensional array: \ n");
for (j=0;j<w;j++)
for (i=0;i<l;i++)
scanf ("%d", &rect[j][i]);
Result=rect (Rect);
printf ("The%d\n of the maximum sub-array:", result);
return 0;
}

Iii. Results of operation

Iv. Work Experience

The first time in charge of code review, but also the first time sitting next to classmates, see the students programming, pick out his program errors, to his program to test, let me harvest a lot, some errors, write the program when it is difficult to find, but see the program when you can see.

V. Work photos

Pair Development 5

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.