Pair development--a cyclic one-dimensional array to find the maximum number of sub-arrays

Source: Internet
Author: User

Pair of people: Han Xiedong, Gao Gao

First, design ideas

This programming we mainly based on the previous program, on this basis by changing the position of the array elements, the formation of a new array, and by calling us before the maximum value of the function to find the maximum value of each array, and then after the comparison to obtain results.

Second, the source code

//Shuzuhuan0327.cpp:Defines the entry point for the console application.//Han Xiedong, Gao Gao//Time: 2015/3/27#include"stdafx.h"#include"stdio.h"#include"stdlib.h"#include"time.h"intShuchu (intM[],intSZCDX,intXhy)//m[] represents the array to test, SZCHX represents the array length, Xhy represents the loop condition{    intt,p; intmax,sum; //Cache Array Assignment    intc[Ten]; intv[Ten];  for(t=szcdx-xhy-1; t<szcdx;t++) {c[t-szcdx+xhy+1]=M[t]; }    //Loops     for(t=xhy;t>=0; t--) {sum=0;  for(p=0;p <=t;p++) {sum=sum+C[p]; } V[t]=sum; }    //cyclic output Maximum valuemax=v[0];  for(t=0; t<xhy+1; t++)    {        if(max<=V[t]) {Max=V[t]; } printf ("%d", v[t]); }        returnMax;}intMainintargcChar*argv[])    {Srand (Time (NULL)); inta[Ten]; intb[Ten];  for(intj=0;j<Ten; j + +) {A[j]=rand ()%Wuyi- -; printf ("%d", A[j]); }    intmaxx[Ten]; printf ("\ n");  for(intI=9; i>=0; i--) {printf ("the and of all adjacent sub-arrays containing the number of%d in the array:",Ten-i); Maxx[i]=shuchu (A,Ten, i); printf ("\n%d\n\n", Maxx[i]); }    intmaxxx=maxx[0];  for(i=0;i<Ten; i++)    {        if(maxxx<=Maxx[i]) {maxxx=Maxx[i]; }} printf ("\ n \ nthe maximum value of all the sub-arrays of the array:%d\n\n", maxxx); b[0]=maxxx; intp;  for(intt=0;t<9; t++) {p=a[0];  for(intq=0;q<9; q++) {A[q]=a[q+1]; } a[9]=p; //int maxx[10];                 for(intI=9; i>=0; i--) {printf ("the and of all adjacent sub-arrays containing the number of%d in the array:",Ten-i); Maxx[i]=shuchu (A,Ten, i); printf ("\n%d\n\n", Maxx[i]); }        intmaxxx=maxx[0];  for(i=0;i<Ten; i++)        {            if(maxxx<=Maxx[i]) {maxxx=Maxx[i]; }} printf ("\ n \ nthe maximum value of all the sub-arrays of the array:%d\n\n", maxxx); B[t+1]=maxxx; }    intMa; Ma=b[0];  for(i=0;i<Ten; i++)    {        if(ma<=B[i]) {Ma=B[i]; }} printf ("\ n \ nthe maximum value of all the sub-arrays of the array:%d\n\n", MA); return 0; }

Iii. Results

According to the number of elements in the array, generate an array of equal numbers, respectively, the maximum number of words for the group and, in comparison, the maximum value!

Iv. Experience

This time the teacher added a bit of difficulty, but we feel it is not difficult to solve, in class soon have ideas, have to say that the scalability of the previous programming is really important. With the basis of the previous, we consider how to use the former to improve the present, so that greatly reduce the workload, reduce the difficulty of programming, in the future to develop a good habit of compiling a scalable program.

V. Drawings

Pair development--a cyclic one-dimensional array to find the maximum number of sub-arrays

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.