POJ-1006-生理周期

来源:互联网 发布:唐朝 知乎 编辑:程序博客网 时间:2024/06/09 18:49

题目链接:http://poj.org/problem?id=1006&lang=zh-CN

要求输入四个整数,分别是体力、感情、智力从当年第一天开始出现高峰的天数,以及给定的时间。求给定时间到下一次三个高峰同时出现的时间。

我的代码

#include <iostream>using namespace std;int main(){int p, e, i, d, theday, n=1;cin >> p >> e >> i >> d;while (!(p == -1 && e == -1 && i == -1 && d == -1)){p %= 23;e %= 28;i %= 33;theday = p;while (theday%28!=e || theday%33!=i)theday += 23;if (theday <= d) theday += 21252;cout << "Case " << n << ": the next triple peak occurs in " << theday - d << " days." << endl;n++;cin >> p >> e >> i >> d;}return 0;}


个人认为难点主要是:

一、两个while的条件的判断;

二、几种特殊情况(如三个高峰同时出现的时间与给定的时间是同一天)的处理

0 0
原创粉丝点击