# Task 4 Max and the contiguous subarray of the array (team work)

Source: Internet
Author: User

Group members: Li Min, Liu Zixiang

1. Design idea: Because this topic has been done, as long as the previous program plus the corresponding test and constraints can be. After consulting with two of us, we decided on the main framework of the program and listed the functions that could be implemented in the end. First define the array length and the upper and lower bounds of the variable, and then through the IF statement to determine the length and value given by the user to see if it is legal, if not legal to re-enter. Finally add the corresponding code of the previous summation.

2. Problems arise: After we have reached an agreement, Li Min is responsible for programming and I am responsible for testing. began to write the program, in writing to determine whether the value of the int integer range of errors occurred when I was in the test, I found that she put the less than the wrong number of the greater than, and then corrected. There are also a few details of the symbolic error. Finally, I made some suggestions about the code specification of the program she wrote, such as the variable name specification, a single row of parentheses, and a blank space. All the work has been done after all the corrections have been made.

3. Source code:

`//Max and (after test) of contiguous Subarray in array//Liu Zixiang 2015/3/29#include <iostream>#include<time.h>using namespacestd;voidMain () {intarr[ +]; intlength,max,min; CharIfcontinue ='Y';    Srand ((unsigned) time (NULL));  while(Ifcontinue = ='Y') {cout<<"Please enter the length of the array:" ; CIN>>length; cout<<"Please enter the min and Max values for this array max:"; CIN>> MIN >>MAX; //Checks whether the upper and lower values of the array range are legal        if(MIN > Max| | MIN <=-2147483648|| MAX >=2147483647) {cout<<"the number entered is not valid, please re-enter:"<<Endl; CIN>> MIN >>MAX; }        //checking the legitimacy of array lengths        if(Length = =0) {cout<<"the array length cannot be zero, please re-enter:"; CIN>>length; }        Else if(Length >= +|| Length > Max-min)//ensure that there are no duplicate numbers in the array{cout<<"the array length is too long, please enter the array length within 1000:"; CIN>>length; }        //checking the legitimacy of array lengthscout<<"The resulting array is:"<<Endl;  for(inti =0; i < length; i++) {Arr[i]= rand ()% ( Max-min +1) + MIN;//generate a random arraycout << Arr[i] <<"   "; } cout<<Endl; //The maximum and the current sub-array are calculated in order of the array        intTran = arr[0]; intsum =Tran;  for(intj =1; J < length; J + +) {Tran= max (Arr[j],tran +Arr[j]); Sum=Max (sum, Tran); }         //Considering that the array is contiguous (that is, the array can be visualized as a circle), the sum of the maximal sub-arrays of the two ends that are not met before each other are simultaneously made from the first and end of the array .        intI,J,SUM1 = arr[0];  for(i =1; I < length && sum1 + arr[i] > sum1; i++) {sum1+=Arr[i]; } Tran=Arr[length];  for(j = Length-1; J >=1&& Tran + arr[j] > tran; j--) {Tran+=Arr[j]; }        //compares the sum of the two largest sub-arrays that were not met before the two ends of the array, and the sum of the largest sub-arrays that were calculated in order of the array in turn        if(I < J && Sum1 + Tran >sum) {Sum= Sum1 + tran;//the sum of the maximum number of words in two cases} cout<<"The maximum value of the sum of successive sub-arrays of the array is:"<< sum <<Endl; cout<<"do you want to continue testing? Please enter: (y/n)"<<Endl; CIN>>ifcontinue; }    }`

4. Test:

5. Summary: (1) through two pairs of people to cooperate, I realized the "1+1>2", because two people must have at least two ideas, through a relatively good cooperation can work together to improve work efficiency; In the case of problems, you can find data quickly find a solution Of course, we also have a number of views of the situation is not uniform, then need to communicate in a timely manner, if there is a right and wrong points, can be corrected in time, otherwise it will be improved. After the study and work will presumably have a lot of cooperation, to deal with the relationship between teammates, clear division of labor in a timely manner can indeed be their own level to improve faster, but also to broaden their thinking.

(2) This procedure I put emphasis on the test and code specifications, because usually used to write C + +, my own shortcomings are: not too much love to write comments, variables and parameter names sometimes do not follow the norms, hope that their future attention.

In addition, the teacher has always emphasized the importance of Java, so on the internet to find Java code specification, convenient for later control

Figures:

Task 4 Max and the contiguous subarray of the array (team work)

Related Keywords:

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.