41. And for S of two digits vs and continuous positive sequence for s

Source: Internet
Author: User


BOOL Findnumberswithsum (int data[], int length, int sum, int* num1, int* num2)
{
BOOL found = false;
if (Length < 1 | | num1 = = NULL | | num2 = = NULL)
return found;
int ahead = Length-1;
int behind = 0;
while (ahead > behind)
{
Long Long cursum = Data[ahead] + data[behind];
if (cursum = = SUM)
{
*NUM1 = Data[behind];
*num2 = Data[ahead];
Found = true;
Break
}
else if (cursum > Sum)
ahead--;
Else
behind++;
}
return found;
}

The time complexity is O (n).



void findcontinuoussequence (int sum)
{
if (Sum < 3)
Return
int small = 1;
int big = 2;
int middle = (1 + sum)/2;
int cursum = small + big;
while (Sum<middle)
{
if (cursum = = SUM)
Printcontinuoussequence (small, big);
while (Cursum > Sum&&small < middle)
{
Cursum-= small;
small++;
if (cursum = = SUM)
Printcontinuoussequence (small, big);
}
big++;
Cursum + = big;
}
}
void printcontinuoussequence (int small,int big)
{
for (int i = small; I <= big; ++i)
printf ("%d", I);
printf ("\ n");
}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

41. And for S of two digits vs and continuous positive sequence for s

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.