Biorhythms Problem

Biorhythms Problem

description:

Some people believe that there are three cycles in a person's life that start the day he or she is born. These three cycles are the physical, emotional, and intellectual cycles, and they have periods of lengths 23, 28, and 33 days, respectively. There is one peak in each period of a cycle. At the peak of a cycle, a person performs at his or her best in the corresponding field. Since the three cycles have different periods, this problem asks students to determine when a triple peak occurs (the peaks of all three cycles occur in the same day) for any person.

source:

right:huanghaoxiang

--------------------------------------------------------------------------------------------------

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

wrong 1: Gohome

--------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------

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

--------------------------------------------------------------------------------------------------

wrong2: jellon

--------------------------------------------------------------------------------------------------

#include <stdio.h>int main(){ int i, j, d, tmp,count; long re; int sum = 21252; int n[3] = {23, 28, 33}, c[3], m[3]; count = 0; while(++count) { scanf("%d%d%d%d",&c[0],&c[1],&c[2],&d); if(d == -1) break; for(i = 0; i < 3; i++) { m[i] = sum/n[i]; tmp = m[i]%n[i]; for(j = 1; j < n[i]; j++) { if(tmp*j % n[i] == 1) break; } m[i] *= j; } re = 0; for(i = 0; i < 3; i++) re += m[i]*c[i]; re %= sum; if(re == 0) re += sum; if(re > d) printf("Case %d: the next triple peak occurs in %ld days.\n",count,re-d); else printf("Case %d: the next triple peak occurs in %ld days.\n",count,sum); } return 0;}

--------------------------------------------------------------------------------------------------

wrong3:cqh87

--------------------------------------------------------------------------------------------------

#include<iostream>using namespace std;int min(long* a){ int i=a[1]<a[2]?1:2; return a[i]<a[3]?i:3;}int main(){ long time=1; long a[5]; int c[4]={0,23,28,33}; cin>>a[1]>>a[2]>>a[3]>>a[4]; while(a[1]!=-1&&a[2]!=-1&&a[3]!=-1&&a[4]!=-1){ while(a[1]<=a[4])a[1]+=c[1]; while(a[2]<=a[4])a[2]+=c[2]; while(a[3]<=a[4])a[3]+=c[3]; while(a[1]!=a[2]||a[2]!=a[3]){ int t=min(a); a[t]+=c[t]; } cout<<"Case "<<time<<": the next triple peak occurs in "<<a[1]-a[4] <<" days."<<endl; cin>>a[1]>>a[2]>>a[3]>>a[4]; time++; }//cout<<"Case 6: the next triple peak occurs in 10789 days."<<endl; ////system("pause");

}

--------------------------------------------------------------------------------------------------

wrong4: cs10107_00730030

--------------------------------------------------------------------------------------------------

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

}

--------------------------------------------------------------------------------------------------

wrong5: dingxiaoguang

--------------------------------------------------------------------------------------------------

#include <iostream>using namespace std;int main(){ int k = 1; while(1) { int a,b,c,d; cin>>a>>b>>c>>d; if( a + b + c + d == -4 ) break; int x; for( x = d + 1 ; x < 21253 ; x ++ ) { if( ( x - a ) % 23 == 0 && ( x - b ) % 28 == 0 && ( x - c ) % 33 == 0 ) { cout<<"Case "<<k++<<": the next triple peak occurs in "<<x-d<<" days."<<endl; break; } } } return 0;

}

--------------------------------------------------------------------------------------------------