poj1006_Biorhythms

  英语真差劲啊,看题目没看明白,无奈重新开始手抄题目,突然发现一句话 “For each cycle,you will be given the number of days form the beginning of the current year at which one of its peaks occurs. " 看到这句才反应过来应该把前三个值分别取余,好笨啊!

 1 #include <stdio.h>
 2 #include <math.h>
 3 int main(){
 4     int k,i,n,j;
 5     int a,b,c,d;
 6     int cnt=0;
 7     while(~scanf("%d%d%d%d",&a,&b,&c,&d)){
 8         if(a==-1&&b==-1&&c==-1&&d==-1)
 9             break;
10         a=a%23;b=b%28;c=c%33;
11         for(i=1;i<=1000000;++i){
12             if(i<a||i<b||i<c) continue;
13             if( ((i-a)%23==0) && ((i-b)%28==0) && ((i-c)%33==0) ){
14                 if(d>=i){
15                     printf("Case %d: the next triple peak occurs in %d days.
",++cnt,i-d+23*28*33);
16                 }else 
17                     printf("Case %d: the next triple peak occurs in %d days.
",++cnt,i-d);
18                 break;
19             }
20         }
21     }
22     return 0;
23 }
原文地址:https://www.cnblogs.com/symons1992/p/3502354.html