-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1154.cpp
More file actions
57 lines (55 loc) · 1.41 KB
/
1154.cpp
File metadata and controls
57 lines (55 loc) · 1.41 KB
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
class Solution
{
public:
int dayOfYear(string date)
{
long long num = 0;
int year = stoi(date.substr(0, 4));
int month = stoi(date.substr(5, 2));
int day = stoi(date.substr(8));
bool runnian = false;
if((year%4 == 0 && year%100 != 0) || year%400 == 0 ) {
runnian = true;
}
num += day;
month--;
for(int i= month;i>0;i--)
{
switch (i)
{
case 1:num += 31;
break;
case 2:
if(runnian)
{
num += 29;
break;
}
else
{
num += 28;
break;
}
case 3:num += 31;
break;
case 4:num += 30;
break;
case 5:num += 31;
break;
case 6:num += 30;
break;
case 7:num += 31;
break;
case 8:num += 31;
break;
case 9:num += 30;
break;
case 10:num += 31;
break;
case 11:num += 30;
break;
}
}
return num;
}
};