C ++ basic algorithm learning-physiological cycle, basic algorithm physiological cycle
People have physical strength, emotional intelligence, IQ peak days, they are every
Appears on 23, 28, and 33 days. For everyone, we want
Know when the three peaks fall on the same day. Given three peaks
The day p, e, And I (not necessarily the day when the first peak appears ),
Given another specified day d, your task is to output day d
Then, the next three peaks fall on the same day (distance d
). For example, if the given day is 10, three will appear next time.
When the day of the peak is 12, the output is 2.
11 physiological cycle
Input
Enter four integers: p, e, I, and d. P, e, And I indicate physical strength, emotion, and
The day when the peak of Intelligence appears. D is the given day, which may be less than p, e, or I.
All given days are not negative and less than or equal to 365, and the days are less
Or equal to 21252.
Output
From the given day to the day of the next three peaks (from the given day
Days ).
12 physiological cycle
Input example
0 0 0 0
0 0 0 100
5 20 34 325
4 5 6 7
283 102 23 320
203 301 203 40
-1-1-1-1
13 physiological cycle
Output example
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.
# Include <iostream> using namespace std; int main () {int p, e, I, d; cout <"Enter the values of d, p, e, And I: "<endl; cin> e> I> d> p; int k; for (k = d + 1; (k-p) % 23; k ++); for (; (k-e) % 28; k = k + 23); for (; (k-I) % 33; k = k + 23*28); cout <(k-d) <"three peaks appear in days" <endl; return 0 ;}