[Face Test] monkey points peach recursive Super Concise code

Source: Internet
Author: User

Ps: Brother do not understand what 5^5-4, brother only use code to speak, a line of recursion directly return to fix, the whole network the most awesome code, not one.

Ps: Reprint Please specify the Source: Liaocheng University Sun Yupeng. Thank you.

5 Monkeys a peach, the 1th only first to, will be the average peach divided into 5, found one more, ate this one, and took their own, the 2nd monkey came to see only 4,

He did not know that had been divided, and also the peach on average 5, found that one more, he also ate this one, and took his own that, the 3rd monkey came to see the ground Also

Only 4, he also divided the peach average of 5, also found one more, he also like them, ate this one, also took away his own, the 4th monkey is also divided 5,

Eat a lot of one, took their own that part, the 5th monkey came, the same as the remaining 4 of the average divided into 5, but also a more, eat, ask how many peaches a total.

#include <stdio.h>

int devide (int result, int sum, int i, int monkey)
{result
    = i = = 1? sum:result;< C3/>return result% Monkey = 1? (i = = = = = = = Monkey Sum:devide (result-1)/5 * 4, SUM, i+1, monkey)): Devide (Result, sum+1, 1, monkey);
}

int main ()
{
    printf ("Number of Peaches is:%d\n", devide (0, 0, 1, 5));
    return 0;
}

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.