First, title:
Returns the and of the largest sub-array in an integer array.
Requirements:
1. Enter an array of shapes with positive and negative numbers in the array.
2. One or more integers in the array make up a sub-array, each of which has a and.
3. Ask for the maximum value of all sub-arrays. Requires a time complexity of O (n).
Second, design ideas
1. First, respectively, the number of elements of the array .... The largest of the array and
2. The maximum and composition of the array of the number of different elements will be calculated as a new array.
3. Find out the maximum number in the new array
4. Finally, the total positive, all negative, and positive negative numbers are used for detection.
Third, the source code
Package Com.minirisoft;import java.util.*;import java.util.*;class shuzu{public static void Main (string[] args) { Scanner sc=new Scanner (system.in); int[] List = new int[10];//The input array is an array that must be defined before an error occurs! int[] arr1 = new int[9];//input array is an array that must be defined before an error occurs! int[] arr2 = new int[8];//input array is an array that must be defined before an error occurs! int[] Arr3 = new int[7];//input array is an array that must be defined before an error occurs! int[] Arr4 = new int[6];//input array is an array that must be defined before an error occurs! int[] Arr5 = new int[5];//input array is an array that must be defined before an error occurs! int[] Arr6 = new int[4];//input array is an array that must be defined before an error occurs! int[] arr7 = new int[3];//input array is an array that must be defined before an error occurs! int[] Arr8 = new int[2];//input array is an array that must be defined before an error occurs! int[] Ma = new int[10];//The input array is an array that must be defined before an error occurs! int i=0,sum = 0; SYSTEM.OUT.PRINTLN ("Please input array:"); for (int k=0;k<10;k++) {list[k]=sc.nextint ();} int Max=list[0];for (i=0;i<10;i++) {if (List[i]>max) {max=list[i];}} Ma[0] = max; SYSTEM.OUT.PRINTLN ("There are 1 elements of the largest sub-array and" +ma[0]); for (i=0;i<9;i++) {arr1[i] = list[i]+list[i+1];} int Max1=arr1[0];for (i=0;i<9;i++) {if (ARR1[I]>MAX1) {max1=arr1[i];}} MA[1]=MAX1; SYSTEM.OUT.PRINTLN ("There are 2 elements of the largest sub-array and" +ma[1]); for (i=0;i<8;i++) {arr2[i] = list[i]+list[i+1]+list[i+2];} int Max2=arr2[0];for (i=0;i<8;i++) {if (ARR2[I]>MAX2) {max2=arr2[i];}} MA[2]=MAX2; SYSTEM.OUT.PRINTLN ("There are 3 elements of the largest sub-array and" +ma[2]); for (i=0;i<7;i++) {arr3[i] = list[i]+list[i+1]+list[i+2]+list[i+3];} int Max3=arr3[0];for (i=0;i<7;i++) {if (arr3[i]>max3) {max3=arr3[i];}} MA[3] = max3; SYSTEM.OUT.PRINTLN ("There are 4 elements of the largest sub-array and" +ma[3]); for (i=0;i<6;i++) {Arr4[i] = list[i]+list[i+1]+list[i+2]+list[i+3]+ LIST[I+4];} int Max4=arr4[0];for (i=0;i<6;i++) {if (arr4[i]>max4) {max4=arr4[i];}} MA[4] = max4; SYSTEM.OUT.PRINTLN ("There are 5 elements of the largest sub-array and" +ma[4]); for (i=0;i<5;i++) {Arr5[i] = list[i]+list[i+1]+list[i+2]+list[i+3]+ LIST[I+4]+LIST[I+5];} int Max5=arr5[0];for (i=0;i<5;i++) {if (arr5[i]>max5) {max5=arr5[i];}} MA[5] = max5; SYSTEM.OUT.PRINTLN ("There are 6 elements of the largest sub-array and" +ma[5]); for (i=0;i<4;i++) {Arr6[i] = list[i]+list[i+1]+list[i+2]+list[i+3]+ LIST[I+4]+LIST[I+5]+LIST[I+6];} int Max6=arr6[0];for (i=0;i<4;i++) {if (arr6[i]>max6) {max6=arr6[i];}} MA[6] = max6; System.out.println ("has 7 elements of the largest subarray and is" +ma[6]); for (i=0;i<3;i++) {arr7[i] = list[i]+list[i+1]+list[i+2]+list[i+3]+list[i+4]+list[i+5]+list[i+6]+list[i+7];} int Max7=arr7[0];for (i=0;i<3;i++) {if (ARR7[I]>MAX7) {max7=arr7[i];}} MA[7] = max7; SYSTEM.OUT.PRINTLN ("There are 8 elements of the largest sub-array and" +ma[7]); for (i=0;i<2;i++) {Arr8[i] = list[i]+list[i+1]+list[i+2]+list[i+3]+ LIST[I+4]+LIST[I+5]+LIST[I+6]+LIST[I+7]+LIST[I+8];} int Max8=arr7[0];for (i=0;i<2;i++) {if (arr8[i]>max8) {max8=arr8[i];}} MA[8] = max8; System.out.println ("The sum of the largest sub-arrays with 9 elements is" +ma[8]); for (i=0;i<10;i++) {sum = Sum+list[i];} MA[9] = sum; SYSTEM.OUT.PRINTLN ("There are 10 elements of the largest subarray and" +ma[9 "); int max9=ma[0];for (i=0;i<10;i++) {if (ma[i]>max9) {max9=ma[i];}} System.out.println ("Maximum subarray of +max9");}}
Iv. Results of the experiment
Five, experience
Doing so many experiments, the first attempt to team up to do experiments, feel that team have good and bad bar. The advantage is that we can get more ideas from the team members, the bad is that everyone has their own ideas,
When ideas do not have to spend time to communicate with each other, do not do their own easy. But I feel I should practice teamwork, after all, work is a team work, learn how to better and group communication and cooperation
Will lay a better foundation for their future work.
VI. panel members: Yang Guangxin, Guo Jianhao
Pair development---to find the largest subarray of an array and