Description
Tell you a little secret: oyster is actually a Martian!
After living on earth for so many years, oyster began to miss home. However, the ship that went home was not as open as a bus on the road, so he ran BUAA, determined the launch time of the next Mars detector, and recorded it on the calendar, then I pulled a tent and started hibernation.
When oyster woke up, it was a matter of many days later, and even the detector was no longer ready to take off, however, the powerful "hibernation clock" in his subconscious tells him that the launch time is within the plus or minus seven days of the current time. He bought a newspaper and knew the current date. But how many days has it been before the detector was launched? Oyster is not easy to calculate.
In order to send oyster back to Mars, this task is handed over to the smart ones.
Input
The input includes multiple groups of test data. The first row has only one integer t to indicate the number of test data groups.
Each line in the following T rows represents a group of test data in the following format:
M/D/y m/d
M, D, and Y are numbers. M/D/Y represents a complete date, which is the date when the detector was launched. M/D indicates a date displayed in the newspaper. The two are separated by a space.
Output
For each group of test data, your program provides the following output:
Output status
M/D/Y is n day (s) Prior |
If the newspaper date is within seven days before the launch date |
M/D/Y is n day (s) after |
If the newspaper date is within seven days after the launch date |
Same day |
The date in the newspaper is the same as the launch date. |
Out of range |
The time in the newspaper cannot be within the plus or minus seven days of the launch date. |
Example input 7
11/20/2008 11/21
11/20/2008 11/17
11/20/2008 11/20
11/20/2008 11/13
11/20/2008 11/28
1/2/2008 12/30
12/31/2100 1/3 sample output
11/21/2008 is 1 day after
11/17/2008 is 3 days prior
Same day
11/13/2008 is 7 days prior
Out of range
12/30/2007 is 3 days prior
1/3/2101 is 3 days after
Solution:
This is another simulated question.
Obtain the current date and compare it with the current date. Pay attention to the leap year. Nothing else can be said, which is relatively simple.
#include <iostream>#include <cstdio>#include <cmath>using namespace std;int getDays(int year,int month){if(month == 2){if((year%4==0 && year%100 != 0)||year%400 == 0)return 29;else return 28;}else{switch(month){case 1:case 3:case 5:case 7:case 8:case 10:case 12:return 31;default:return 30;}}}int main(){int t,month,day,year,month1,day1,temp;cin>>t;while(t--){scanf("%d/%d/%d %d/%d",&month,&day,&year,&month1,&day1);if(month!=12 && month!=1 && abs(month1-month)>1)cout<<"OUT OF RANGE "<<endl;else {/*if(month == 2 && month1 == 3){temp=getDays(year,month)-day+day1;if( temp> 7)cout<<"OUT OF RANGE "<<endl;elsecout<<month1<<"/"<<day1<<"/"<<year<<" IS "<<temp<<" DAY AFTER "<<endl;}else*/if(month == month1){temp=day-day1;if(temp == 0)cout<<"SAME DAY "<<endl;else if(temp>0 && temp<8){if(temp == 1)cout<<month1<<"/"<<day1<<"/"<<year<<" IS "<<temp<<" DAY PRIOR "<<endl;elsecout<<month1<<"/"<<day1<<"/"<<year<<" IS "<<temp<<" DAYS PRIOR "<<endl;}else if(temp <0 && temp> -8){if(temp == -1)cout<<month1<<"/"<<day1<<"/"<<year<<" IS "<<-1*temp<<" DAY AFTER "<<endl;elsecout<<month1<<"/"<<day1<<"/"<<year<<" IS "<<-1*temp<<" DAYS AFTER "<<endl;}else cout<<"OUT OF RANGE "<<endl;}else if(month > month1){if(month ==12){year++;temp=31-day+day1;if(temp >7)cout<<"OUT OF RANGE "<<endl;else{if(temp ==1)cout<<month1<<"/"<<day1<<"/"<<year<<" IS "<<temp<<" DAY AFTER "<<endl;elsecout<<month1<<"/"<<day1<<"/"<<year<<" IS "<<temp<<" DAYS AFTER "<<endl;}}else{temp=getDays(year,month1)-day1+day;if(temp >7)cout<<"OUT OF RANGE "<<endl;else {if(temp ==1)cout<<month1<<"/"<<day1<<"/"<<year<<" IS "<<temp<<" DAY PRIOR "<<endl;elsecout<<month1<<"/"<<day1<<"/"<<year<<" IS "<<temp<<" DAYS PRIOR "<<endl;}}}else if(month < month1){if(month == 1){year--;temp=31-day1+day;if(temp >7)cout<<"OUT OF RANGE "<<endl;else{if(temp ==1)cout<<month1<<"/"<<day1<<"/"<<year<<" IS "<<temp<<" DAY PRIOR "<<endl;elsecout<<month1<<"/"<<day1<<"/"<<year<<" IS "<<temp<<" DAYS PRIOR "<<endl;}}else{temp=getDays(year,month)-day+day1;if(temp >7)cout<<"OUT OF RANGE "<<endl;else {if(temp ==1)cout<<month1<<"/"<<day1<<"/"<<year<<" IS "<<temp<<" DAY AFTER "<<endl;elsecout<<month1<<"/"<<day1<<"/"<<year<<" IS "<<temp<<" DAYS AFTER "<<endl;}}}}}return 0;}