A - Calandar

On a planet far away from Earth, one year is composed of 12 months, and each month always consists of 30 days.

Also on that planet, there are 5 days in a week, which are Monday, Tuesday, Wednesday, Thursday and Friday. That is to say, if today is Monday, then tomorrow will be Tuesday, the day after tomorrow will be Wednesday. After 3 days it will be Thursday, after 4 days it will be Friday, and after 5 days it will again be Monday.

Today is the d1d_1-th day in the m1m_1-th month of year y1y_1. Given the day of today on that planet, what day will it be (or was it) on the d2d_2-th day in the m2m_2-th month of year y2y_2 on that planet?

Input
There are multiple test cases. The first line of the input contains an integer TT (about 100), indicating the number of test cases. For each test case:

The first line contains three integers y1y_1, m1m_1, d1d_1 (2000y11092000 \le y_1 \le 10^9, 1m1121 \le m_1 \le 12, 1d1301 \le d_1 \le 30) and a string ss, indicating the date and day of today on that planet. It’s guaranteed that ss is either “Monday”, “Tuesday”, “Wednesday”, “Thursday” or “Friday”.

The second line contains three integers y2y_2, m2m_2 and d2d_2 (2000y21092000 \le y_2 \le 10^9, 1m2121 \le m_2 \le 12, 1d2301 \le d_2 \le 30), indicating the date whose day we want to know.

Output
For each test case output one line containing one string, indicating the day of the d2d_2-th day in the m2m_2-th month of year y2y_2 on that planet.

Sample Input
4
2019 5 12 Monday
2019 5 14
2019 5 12 Tuesday
2019 12 30
2019 5 12 Friday
1000000000 1 1
1000000000 1 1 Wednesday
2019 5 12
Sample Output
Wednesday
Friday
Thursday
Thursday

#include<bits/stdc++.h>
using namespace std;

char n[5][10]= {"Monday","Tuesday","Wednesday","Thursday","Friday"};
int main()
{
    std::ios::sync_with_stdio(false);
    int t;
    cin>>t;
    while(t--)
    {
        long long int y,m,d;
        char s[10];
        cin>>y>>m>>d>>s;
        long long int y2,m2,d2;
        cin>>y2>>m2>>d2;
        long long int sum1=0;
        sum1=-(y*360+m*30+d)+(y2*360+m2*30+d2);
        int week=sum1%5;
        if(week<0)//注意是負數的情況
            week+=5;
        int j;
        for(j=0; j<5; j++)
        {
            if(strcmp(n[j],s)==0)
                break;
        }
        cout<<n[(j+week)%5]<<endl;
    }
    return 0;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章