Find the sum of the largest array of words in the first part

Source: Internet
Author: User

First , the title requirement: Returns the largest subarray in an integer array and input an array of shapes, with positive numbers in the array and negative values. One or more consecutive integers in an array make up an array, and each sub-array has one and. Second, the design idea: first enter a string of arrays, define Max as the maximum value, define sum as the sum of the results; start from the beginning by adding the first and sum of the array to sum, judging the positive and negative of a[i], and judging the size of Max and sum for positive numbers, and if the sum is 0 for negative numbers If the final result is Max 0, then the array will be negative, just find the largest negative number.           Outputs the sum of the largest sub-arrays. Third, Code://Lulinlain Yuhuihui 2016.3.26#include<iostream>using namespacestd;intMain () {inta[ -],n;intsum=0, max=0; cout<<"Please input the number of the array:"; Cin>>N;cout<<"Please input"<<N<<"Number :"; for(intI=0; i<n;i++) Cin>>A[i]; for(intI=0; i<n;i++) {sum+=a[i];//assign each sum to sum   if(a[i]>=0)  {     if(max<sum) {Max=sum; }  }   if(sum<0) {sum=0; }}if(max==0) {Max=a[0];  for(intI=1; i<n;i++)    {      if(a[i]>max) Max=A[i]; }}cout<<"The max is:"<<max<<Endl;return 0;} Four, Time: The plan took 4 hours, the actual cost of 7 hours; including debugging procedures and the design of the Zhao program; five, experience: This experiment compared to the previous experiments is relatively simple, as long as the design of the idea of programming to achieve it is relatively easy.

Find the sum of the largest array of words in the first part

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.