-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBJ1308.cpp
More file actions
123 lines (100 loc) · 2.61 KB
/
BJ1308.cpp
File metadata and controls
123 lines (100 loc) · 2.61 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
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include <iostream>
using namespace std;
int leapYear(int Year);
int main() {
int startYear = 0;
int startMonth = 0;
int startDay = 0;
int endYear = 0;
int endMonth = 0;
int endDay = 0;
int yearSum = 0;
int startDaySum = 0;
int endDaySum = 0;
int temp = 0;
cin >> startYear >> startMonth >> startDay;
cin >> endYear >> endMonth >> endDay;
//예외처리
if ((endYear - startYear) == 1000){
if (endMonth >= startMonth && endDay >= startDay){
cout << "gg";
return 0;
}
} else if ((endYear - startYear) > 1000){
cout << "gg";
return 0;
}
//연도 합
for (int i = startYear; i <= endYear; i++){
temp = leapYear(i);
if (temp == 1){
yearSum += 366;
}
if (temp == 0){
yearSum += 365;
}
}
//시작연도 월/일까지 일의 합
// 1월: 31일 2월: 28일 or 29일 3월: 31일 4월: 30일 5월: 31일 6월: 30일 7월: 31일 8월: 31일 9월: 30일 10월: 31일 11월: 30일 12월: 31일
int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
temp = leapYear(startYear);
if (temp == 1) {
if (startMonth - 1 >= 2){
for (int i = 0; i < startMonth - 1; i++){
startDaySum += month[i];
}
startDaySum += 1;
}
else{
for (int i = 0; i < startMonth - 1; i++){
startDaySum += month[i];
}
}
} else if (temp == 0) {
for (int i = 0; i < startMonth - 1; i++){
startDaySum += month[i];
}
}
startDaySum += startDay;
temp = leapYear(endYear);
if (temp == 1) {
if (endMonth - 1 >= 2){
for (int i = 0; i < endMonth - 1; i++){
endDaySum += month[i];
}
endDaySum += 1;
}
else{
for (int i = 0; i < endMonth - 1; i++){
endDaySum += month[i];
}
}
} else if (temp == 0) {
for (int i = 0; i < endMonth - 1; i++){
endDaySum += month[i];
}
}
endDaySum += endDay;
if (temp == 1){
endDaySum = 366 - endDaySum;
} else if (temp == 0){
endDaySum = 365 - endDaySum;
}
yearSum = yearSum - startDaySum - endDaySum;
cout << "D-" << yearSum;
return 0;
}
//윤년 판별 함수
int leapYear(int year) {
if (year % 4 == 0){
if (year % 100 != 0 || year % 400 == 0) {
return 1;
}
else{
return 0;
}
}
else{
return 0;
}
}