Pairs of Members: Van Dey, Zhao Yonghen
I. Title:
Returns the and of the largest sub-array in an integer array.
Two. Requirements:
Requires that the procedure be capable of handling 1000 elements;
Each element is of the int32 type;
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.
Three. Design ideas
In the last experiment, we set the number of arrays can be very well extended, so for the first request to deal with 1000 elements is easier to implement, for the second requirement, we mainly want to determine how big the largest number, that is, when the overflow problem, when the problem occurs when the program how to deal with, By looking at the data, we finally determine the maximum number of values that the program can handle, and then overflow through the output statement to prompt the array.
Four. Source code
1#include <iostream.h>2 3#include <time.h>4 5#include <stdlib.h>6 7 8 9 intMain ()Ten One { A - - the Srand ((unsigned) time (NULL)); - - - + inta[ +]; - + intM//M is the number of each group A at int*sum=New int[ +]; - -cout<<"*********************************"<<Endl; - - for(intI=0;i< +; i++) - in { - to intb; + -B=rand ()%2; the * Switch(b) $ Panax Notoginseng { - the Case 0: + AA[i]=rand () * -; the + Break; - $ Case 1: $ -A[i]=-rand () * -; - the Break; - Wuyi } the -cout<<a[i]<<" "; Wu - if((i%Ten)==9) About $cout<<endl;//10 outputs per line, line break - - - A } + the - $cout<<"*********************************"<<Endl; the the intHe=0; the the for(m=1;m<1001; m++) - in { the the inttemp=0; About the for(intn=0; n<m;n++) the the { + -temp=temp+A[n]; the Bayi } the the for(intk=0; K<= ( +-m); k++) - - { the thesum[k]=0; the the for(intj=k;j< (k+m); j + +)//A[k] is the first number of each group - the { the thesum[k]=sum[k]+A[j];94 the } the the if(sum[k]>temp)98 About { - 101temp=Sum[k]; 102 103 } 104 the }106 107 if(temp>He)108 109 { the 111He=temp; the 113 } the the } the 117 if(he>2100000000)118 119 { - 121cout<<"Array Overflow! "<<Endl;122 123 }124 the Else126 127 { - 129cout<<"the number of the largest sub-arrays is:"<Endl; the 131 } the 133cout<<"*********************************"<<Endl;134 135 return 0;136 137}
Five. Running
VI. Impressions
The experiment was a random occurrence where we stayed for a long time, mostly unaware that the RAND function also had a value range. In the development of the group, we all have a bit of our own ideas. Finally summed up together, especially in the process of programming, we all want to write a little, a program is always in the style of adding their own design ideas and code. I think a team should also be the style and norms as far as possible, in order to let the team work better.
Report:
Pair Development 4----Maximum sub-array (large number overflow)