POJ 1006 Biorhythms 生理周期 水题

POJ 1006 Biorhythms,同百炼2977 生理周期

注意边界条件

#include <iostream>
using namespace std;

int mod (int a, int b)
{
    if (a >= 0)
        return a%b;
    else
        return (b-(-a)%b)%b;
}
int main(void)
{
    int a, b, c, t;
    int r;
    for (int i = 1; ; i++)
    {
        cin >> a >> b >> c >> t;
        if (a < 0)    break;
        for (r = t + 33 - mod(t-c,33);;r+=33)
        {
            if (mod(r-a,23))
                continue;
            if (mod(r-b,28))
                continue;
            break;
        }
        cout << "Case "<< i << ": the next triple peak occurs in " << r-t << " days." <<endl;
    }
    return 0;
}

posted on 2012-05-28 20:48  澄哥  阅读(254)  评论(0编辑  收藏  举报

导航