剑指Offer40 和为s的连续正数序列

 /*************************************************************************
> File Name: 40_ContinuesSequenceWithSum.c
> Author: Juntaran
> Mail: JuntaranMail@gmail.com
> Created Time: 2016年09月04日 星期日 15时52分42秒
************************************************************************/ #include <stdio.h> void PrintSmallToBig(int left, int right)
{
for (int i = left; i <= right; ++i)
printf("%d ", i);
printf("\n");
} // 输出所有和为sum的连续正数序列,至少两个数
void FindContinuesSequence(int sum)
{
if (sum < )
return; int left = ;
int right = ;
int middle = ( + sum) / ;
int current = left + right; while (left < middle)
{
if (current == sum)
PrintSmallToBig(left, right); while (current>sum && left<right)
{
current -= left;
left ++; if (current == sum)
PrintSmallToBig(left, right);
}
right ++;
current += right;
}
} int main()
{
int sum = ;
FindContinuesSequence(sum); return ;
}
上一篇:DataTables获取指定元素的行数据


下一篇:hadoop生态系统学习之路(八)hbase与hive的数据同步以及hive与impala的数据同步