-
Notifications
You must be signed in to change notification settings - Fork 0
/
first+.cpp
86 lines (75 loc) · 1.64 KB
/
first+.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include<bits/stdc++.h>
#include <iomanip>
using namespace std;
int month[14] = {0, 31,28,31,30,31,30,31,31,30,31,30,31 };
bool isLeapyear(const int y)
{
if (y%400==0) return true;
if (y % 4 == 0 && y % 100 != 0) return true;
return false;
}
/*inline*/ void countMonthday(int startmonth, int endmonth,int& days)
{
for (size_t i = startmonth; i < endmonth; i++)
{
days += month[i];
}
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
vector<int> start(3,0);
auto end = vector<int>(3,0);
char temp;
int weekdayGiven;
for (size_t i = 0; i < 3; i++)
{
cin >> start[i];
}
cin >> weekdayGiven;
cin >> temp;
for (size_t i = 0; i < 3; i++)
{
cin >> end[i];
}
bool swapflag=false;
if (((start[0] - end[0]) * 356 + (start[1] - end[1]) * 30 + (start[0] - end[0])) > 0)
{
swapflag = true;
vector<int> temp = start;
start = end;
end = temp;
}
int days = 0;
bool firflag = isLeapyear(start[0]);
bool secflag = isLeapyear(end[0]);
if (start[0] == end[0]) //same year
{
if (start[1] == end[1])
{//firºÍsecÔÚͬһ¸öÔÂ
days += end[2] - start[2];
}
else
{
days += month[start[1]] - start[2];
countMonthday(start[1] + 1, end[1], days);
days += end[2];
if (firflag && start[1] <= 2 && end[1]>2) days += 1; //´¦ÀíÈòÄê
}
}
else //not same year
{
days += month[start[1]] - start[2];
countMonthday(start[1] + 1, 12, days);
countMonthday(1, end[1], days);
days += end[2];
if (firflag&&start[1] < 2) days += 1;
if (secflag && end[1] > 2) days += 1;
}
int ans=0;
ans = swapflag ? (weekdayGiven - (days % 7) + 7) % 7:((weekdayGiven+(days%7))%7);
cout << ans << endl;
system("pause");
return 0;
}