您的位置:首页 > 编程语言

网易秋招编程题——回文序列

2016-10-17 23:17 197 查看






“test.cpp”

<strong><span style="font-size:18px;">#include<iostream>
using namespace std;

int comb(int* nums,int start,int end)
{
int count = 0;
int left = nums[start];
int right = nums[end];

while(start < end && left != right)
{
if(left < right)
{
left += nums[++start];
count++;
}
else
{
right += nums[--end];
count++;
}
}
if(start > end)
{
return count;
}
else
{
return count += comb(nums,++start,--end);
}
}
void test()
{
int n = 0;
int nums[50] = {0};

cin>>n;
for(int i = 0;i < n;i++)
{
cin>>nums[i];
}

cout<<comb(nums,0,n-1)<<endl;
}
int main()
{
test();
return 0;
}</span></strong>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: