最大联通子数组

#include <iostream>
using namespace std;
#define length1 3
#define length2 5

//*****找出最大值*****
int Largest(int list[],int length)
{
    int i,max=list[0];
    for(i=0;i<length;i++)
    {
        if(list[i]>max)
        {
            max=list[i];
        }
    }
    return max;
}

int main(int argc, char* argv[])
{
    int max1,max2,i;
    int list1[length1];//={10,22,62,45,28,0,-78,-5,3,10};
    int list2[length2];//={-5,-4,-3,-2,-1};
    cout<<"请输入"<<length1<<"个数:";
    for(int i=0;i<length1;i++)
        cin>>list1[i];
    cout<<"请输入"<<length2<<"个数:";
    for(i=0;i<length2;i++)
        cin>>list2[i];
    max1=Largest(list1,length1);
    max2=Largest(list2,length2);
    cout<<endl<<"list1:";
    for(i=0;i<length1;i++)
        cout<<list1[i]<<" ";
    cout<<endl<<"最大值:"<<max1<<endl;
    cout<<"list2:";
    for(i=0;i<length2;i++)
        cout<<list2[i]<<" ";
    cout<<endl<<"最大值:"<<max2<<endl<<endl;
    return 0;
}

posted on 2016-04-02 11:09  897897  阅读(95)  评论(0编辑  收藏  举报

导航