poj1006

来源:互联网 发布:linux使用领域 编辑:程序博客网 时间:2024/05/02 02:29
计算周期,三个周期长度分别为23,28,33,3个分别有一个输入初始值a,b,c,所求数值加上初始值,求其最小公倍数,减去d即可。
即x+d-a%23=
x+d-b%28=
x+d-c%33=0同时满足。
#include<iostream>#include<math.h>using namespace std;  #define  PI 3.1415926int main(void){        int a,b,c,d;    int t=0;    while( cin>>a>>b>>c>>d){        t++;        if(a== -1 &&b==-1 &&c==-1&&d==-1)          return 0;        int flag = 0;        for(int i=1;;i++){            if((i+d-a)%23 == 0 and (i+d-b)%28  == 0&&(i+d-c)%33 == 0){                flag = 1;                cout<<"Case "<<t<<": the next triple peak occurs in "<<i<<" days."<<endl;            }             if(flag==1)              break;           }        }            //system("pause");    return 0;    }    
                                             
0 0
原创粉丝点击