清泉逐流

做着努力,等待幸福到来

Poj1006

作者:Eamonn 时间 : 2014-09-09 20:11 分类:C/C++

#include <iostream>
#define MAX_EX_DATE 21252
#define PERIOD_P    23
#define PERIOD_E    28
#define PERIOD_I    33
using namespace std;
int main(int argc, char* argv[])
{
    int p,e,i,d;
    int case_cnt = 1;
       
    while(true)
    {
        int ans;
           
        cin >> p >> e >> i >> d;
           
        if( -4 == p+i+e+d ){
            break;
        }
           
        if(p>=PERIOD_P){
            p = p - p/PERIOD_P*PERIOD_P;
        }
        if(e>=PERIOD_E){
            e = e - e/PERIOD_E*PERIOD_E;
        }
        if(i>=PERIOD_I){
            i = i - i/PERIOD_I*PERIOD_I;
        }
           
        for(int j=0; ;j++){
            ans = PERIOD_P * j + p;
            if( ans % PERIOD_E == e && ans % PERIOD_I == i){
                break;
            }
        }
           
        if(ans<=d){ 
            ans+=(d-ans)/21252*21252+21252;
        } 
        if(ans>d ){
            ans-=d;
        } 
        if(ans>21252){
            ans=21252;
        }
       
        cout << "Case " << case_cnt << ": the next triple peak occurs in "<< ans <<" days."<< endl;
           
        case_cnt ++;
    }
       
       
    return 0;
}


转载注明: http://www.eamonning.com/note/view/33
» 笔记大类