Physiological cycle (c ++ implementation), physiological cycle implementation
Description: There are three physiological cycles in life: physical, emotional, and mental cycles. Their cycles are 23 days, 28 days, and 33 days. One day in each cycle is the peak. On the peak day, people will do well in the corresponding aspects. For example, at the peak of the intelligence cycle, people will be agile, and their energy is easy to concentrate. Because the perimeter of the three cycles is different, the peaks of the three cycles usually do not fall on the same day. For everyone, we want to know when three peaks fall on the same day. For each cycle, we will give the number of days from the first day of the current year to the peak (not necessarily the first peak time ). Your task is to specify the number of days from the first day of the current year, and the output starts from the specified time (excluding the specified time) the next three peaks fall on the same day (days from the given time ). For example, if the given time is 10 and the time of three peaks in the same day is 12 next time, 2 is output (note that this is not 3 ).
Input: enter four integers: p, e, I, and d. P, e, And I indicate the time when the peak of physical strength, emotion, and intelligence occurred (calculated from the first day of the current year ). D is the given time, which may be less than p, e, or I. All the given time values are non-negative and less than 365, and the requested time is less than or equal to 21252.
Output: the time (days from the specified time) of the next three peaks in the same day ).
Input:
0 0 0 00 0 0 1005 20 34 3254 5 6 7283 102 23 320203 301 203 40-1 -1 -1 -1
output:
Case 1: the next triple peak occurs in 21252 days.Case 2: the next triple peak occurs in 21152 days.Case 3: the next triple peak occurs in 19575 days.Case 4: the next triple peak occurs in 16994 days.Case 5: the next triple peak occurs in 8910 days.Case 6: the next triple peak occurs in 10789 days.
1 #include<iostream> 2 using namespace std; 3 4 int cal(int p, int e, int i, int d) 5 { 6 for (int j = 1;; j++) 7 { 8 if ((j - p) % 23==0 && (j - e) % 28==0 && (j - i) % 33==0) 9 return j - d;10 }11 }12 int main()13 {14 int p, e, i, d, n = 0;15 while ((cin >> p >> e >> i >> d) && (p != EOF))16 {17 n++;18 cout << "Case " << n << ": the next triple peak occurs in " << cal(p, e, i, d) << " days." << endl;19 }20 system("pause");21 return 0;22 }