Output
For each test case output one line containing one string, indicating the day of the -th day in the -th month of year 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
题意:给你两个年份,并给出你其中一个年份的日期,计算出另一个年份的日期。(注意此题目给出一周5天,一个月30天)。
思路:先分情况谈论,
年份小的转年份大的,只需要看月份,(第二个月份-第一个月份)如果是个负数则需要((第二个月份+30-第一个月份)%5 然后加到这个星期后面
年份大的转年份小的,只需要看月份,(第一个月份-第二个月份)是个负数则需要(第一个月份+30-第二个月份)%5 然后减到这个星期后面
我们在比赛中总结了一下,只需要一个规律,用(后面的月份+30-前面的月份)%5 直接加到后面的星期上就行了,用两个map存一下就ac了。
AC代码:
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
using namespace std;
typedef long long ll;
int main()
{
map<int,string> s;
map<string,int> s1;
s[1]="Monday";
s[2]="Tuesday";
s[3]="Wednesday";
s[4]="Thursday";
s[0]="Friday";
s1["Monday"]=1;
s1["Tuesday"]=2;
s1["Wednesday"]=3;
s1["Thursday"]=4;
s1["Friday"]=5;
ll t;
cin>>t;
while(t--)
{
ll y1,y2,m1,m2,d1,d2;
string a;
cin>>y1>>m1>>d1>>a;
cin>>y2>>m2>>d2;
ll num=(d2+30-d1)%5;
ll ans=(s1[a]+num)%5;
cout<<s[ans]<<endl;
}
return 0;
}