ZOJ 1110 Dick and Jane

Dick and Jane

Time Limit: 2 Seconds       Memory Limit: 65536 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
 题意:就是计算年龄。
 思路:以最后出生的yertle为基准,因为yertle最后出生,所以过了多少年就是多少岁,不存在进位的问题
按理想状态,设yertle为i岁,那么sp为i+y,pu为i+p,然后12+j-3*i-y-p就是我们要求的i的表达式
若这个式子被3整除,那么大家都正好,否则要么sp少1或者pu少1或者都少1.
若y-p==s那么说明sp没进位,那么再经相同的年数,sp比pu要先进位,所以此时sp++;
若y-p>s那么说明sp进位了,那么经过相同的年数,pu比sp先进位,所以pu++

代码:
#include<stdio.h>


int main()
{
    int s,p,y,j,d;
    int sp,pu,ye;
    while(scanf("%d%d%d%d",&s,&p,&y,&j)!=EOF)
    {
        d=12+j-p-y;
        ye=d/3;
        pu=ye+p;
        sp=ye+y;
        if(d%3==1)
        {
            if(y-p>s)
                pu++;
            else
                sp++;
        }
        else if(d%3>1)
        {
            pu++;
            sp++;
        }
        printf("%d %d %d\n",sp,pu,ye);
    }
   return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值