Dick and Jane
Time Limit: 1 Second Memory Limit: 32768 KB
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?
Each input line contains four non-negative integers: s, p, y, j. For each input line, print a line containing three integers: Spot's age, Puff's age, and Yertle'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
Output for Sample Input
12 7 2 13 7 2 13 7 2
//1110 ==========================================
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
int s,p,y,j;
int a,b,c;
while(cin>>s>>p>>y>>j)
{
a = (s+y+j+12)/3;
b = (-2*s+y+j+12)/3;
c = (-2*s+y+j+12-3*p)/3;
int sum = j + 12 - a - b - c;
while(sum>0)
{
int t = sum/3;
a+= t;
b+= t;
c+= t;
int tt = sum%3;
if(tt==1)
a++;
if(tt==2)
{
a++;
b++;
}
sum/=3;
}
cout<<a<<" "<<b<<" "<<c<<endl;
}
return 0 ;
}
本篇探讨了一道关于DickandJane与其宠物年龄计算的问题,通过解析题目给出的条件,利用数学公式推导出宠物的实际年龄。

1109

被折叠的 条评论
为什么被折叠?



