//#include "header.h" //AnycodeX includes the header.h by default, needn‘t cancle the notation. #include <iostream> using namespace std; int a[]={3,2,4,1,5};//4 int n=5; /******************** E E E E E E EEE E EEEEE *********************/ void fun() { int l=0,r=n-1,lmax=a[0],rmax=a[n-1],count=0; int min=a[0]; int state=0; int k=3; while(r-l > 1) { state=0; (lmax>rmax)?(min=rmax,state=1):(min=lmax); cout<<min<<endl; if(state == 0) { if(min-a[l+1]>0) { count+=min-a[l+1];l++;lmax < a[l]?lmax=a[l]:0;} else{l++;lmax = a[l];} }else { if(min-a[r-1]>0) { count+=min-a[r-1];r--;rmax < a[r]?rmax=a[r]:0;} else{r--;rmax = a[r];} } } cout<<count; } void fun2() { int l=0,r=n-1,lmax=a[0],rmax=a[n-1],count=0; while(r-l > 1) { if(lmax<rmax) { l++; count+=(lmax-a[l])>0?(lmax-a[l]):(lmax=a[l],0); } else { r--; count+=(rmax-a[r])>0?(rmax-a[r]):(rmax=a[r],0); } } cout<<count; } int main() { cout << "Hello,C++ world of AnycodeX!" << endl; fun2(); return 0; }
时间: 2024-12-28 15:46:37