A桶中有多少水?

如果你能算出桶中有多少水,我便许你下山去玩。
有一天,老和尚让小和尚将A桶的水挑到B桶去,可是小和尚却想下山玩,不愿意挑水,
老和尚便说:”如果你能够根据我的提示算出A桶中有多少升水,我便许你下山去玩。”

小和尚欣然接受。
老和尚说道:“在你面前有五个小水桶,它们分别可以装1、2、3、4、5升水。
       如果你每次用其中两个桶去挑水,那么恰好可以挑6次;
       如果你用三个桶去挑水,那么恰好可以挑4次;
       如果你用四个桶去挑水,那么恰好可以挑2次。
       那么,A桶中一共有多少升水?”
聪明的你能想出答案吗?
A、22
B、24
C、26
D、28


#include <stdio.h>
int main()
{
    unsigned char sumOfFiveBuckets = 1 + 2 + 3 + 4 + 5;
    unsigned char buckets[] = { 1, 2, 3, 4, 5 };
    for (int i = 0; i < 4; ++i)
    {
        for (int j = i + 1; j < 5; ++j)
        {
            unsigned char a = 6 * (buckets[i] + buckets[j]);
            for (int x = 0; x < 3; ++x)
            {
                for (int y = x + 1; y < 4; ++y)
                {
                    for (int z = y + 1; z < 5; ++z)
                    {
                        unsigned char b = 4 * (buckets[x] + buckets[y] + buckets[z]);
                        if (a == b)
                        {
                            for (int n = 0; n < 5; ++n)
                            {
                                unsigned char c = 2 * (sumOfFiveBuckets - buckets[n]);
                                if (a == c)
                                    printf("A桶中有%u升水
", a);
                            }
                        }
                    }
                }
            }
        }
    }
    return 0;
}
原文地址:https://www.cnblogs.com/buyishi/p/8111732.html