UVA10257 Dick and Jane题解
题意简述
已知 Dick、Jane、Spot、Puff、Yertle 的年龄关系如下。
- Dick 的年龄是 12 岁(即 Dick 出生至少
12 年且不超过13 年),Jane 的年龄是j 岁。 - 当 Puff 出生时,Spot 的年龄是
s 岁。 - 当 Yertle 出生时,Puff 的年龄是
p 岁。 - 当 Yertle 出生时,Spot 的年龄是
y 岁。 - Spot、Puff 和 Yertle 的年龄相加,等于 Dick 和 Jane 的年龄和。
现在给定四个非负整数
题目分析
由题意得:设 Yertle 的年龄是
所以,
代码
#include <iostream>
using namespace std;
int s,p,y,j;
int main(){
while (cin >> s >> p >> y >> j){
int tmp = j - y - p + 12,x = tmp / 3;
if (tmp % 3 == 0){
cout << x + y << ' ' << x + p << ' ' << x << endl;
}
else if (tmp % 3 == 1){
if (s + p == y) cout << x + y + 1<< ' ' << x + p << ' ' << x << endl;
else cout << x + y << ' ' << x + p + 1 << ' ' << x << endl;
}
else{
cout << x + y + 1 << ' ' << x + p + 1 << ' ' << x << endl;
}
}
return 0;
}