双11狂欢大促

盲盒赢 定制羽绒服

开启惊喜盲盒,抽取你的专属好礼

— 惊喜奖品抢先看 —

高手帮看下这道题为什么不能输出

longbeing longbeing 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
#include <iostream>
using namespace std;
void main()
{
int n;
int pData[]={1,-2,3,4,5,-7};
int p=sizeof(pData)/sizeof(pData[0]);
bool FindGreatestSumOfSubArray(int pData[],unsigned int p, int n);

cout<<n<<endl<<p<<endl;


}

bool FindGreatestSumOfSubArray
(
int *pData, // an array
unsigned int nLength, // the length of array
int &nGreatestSum // the greatest sum of all sub-arrays
)
{
// if the input is invalid, return false
if((pData == NULL) || (nLength == 0))
return false;

int nCurSum = nGreatestSum = 0;
for(unsigned int i = 0; i < nLength; ++i)
{
nCurSum += pData[i];

// if the current sum is negative, discard it
if(nCurSum < 0)
nCurSum = 0;

// if a greater sum is found, update the greatest sum
if(nCurSum > nGreatestSum)
nGreatestSum = nCurSum;

}


// if all data are negative, find the greatest element in the array
if(nGreatestSum == 0)
{
nGreatestSum = pData[0];
for(unsigned int i = 1; i < nLength; ++i)
{
if(pData[i] > nGreatestSum)
nGreatestSum = pData[i];
}
}

return true;
}

...全文
评论 5
收藏 已收藏
分享
返回顶部
longbeing
C++ 语言 65,214 成员 250,514 内容