UVA10257 ZOJ1110 Dick and Jane【暴力】

Dick is 12 years old. When we say this, we mean that it is at least twelve and not yet thirteen years since Dick was born.
    Dick and Jane have three pets: Spot the dog, Puff the Cat, and Yertle the Turtle. Spot was s years old when Puff was born; Puff was p years old when Yertle was born; Spot was y years old when Yertle was born. The sum of Spot’s age, Puff’s age, and Yertle’s age equals the sum of Dick’s age (d) and Jane’s age (j). How old are Spot, Puff, and Yertle?
Input
Each input line contains four non-negative integers: s, p, y, j.
Output
For each input line, print a line containing three integers:
Spot′s age, P uff′s age, and Y ertle′s age.
Ages are given in years, as described in the first paragraph.
Sample Input
5 5 10 9
5 5 10 10
5 5 11 10
Sample Output
12 7 2
13 7 2
13 7 2

问题链接:UVA10257 ZOJ1110 Dick and Jane
问题简述:(略)
问题分析
    简单数学计算题,暴力枚举一下就好了。
程序说明
    程序中,跳出二重循环用了goto语句。
参考链接:(略)
题记:有时候用goto语句还是很方便的。

AC的C++语言程序如下:

/* UVA10257 ZOJ1110 Dick and Jane */

#include 
#include 

using namespace std;

int main()
{
    int s, p, y, j, a, b, c;
    while(scanf("%d%d%d%d", &s, &p, &y, &j) != EOF) {
        for(a = 12 + j - 1; a >= s + p; a--)
            for(b = p; b <= 12 + j - a; b++) {
                c = 12 + j - b - a;
                if((a == b + s || a == b + s + 1) &&
                        (b == c + p || b == c + p + 1) &&
                        (a == c + y || a == c + y + 1))
                    goto output;
            }

        output:
        printf("%d %d %d\n", a, b, c);
    }

    return 0;
}

你可能感兴趣的:(#,ICPC-备用二,#,ICPC-暴力枚举,#,ICPC-UVA,#,ICPC-ZOJ)