-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Silver V] Title: D-Day, Time: 128 ms, Memory: 14392 KB -BaekjoonHub
- Loading branch information
Showing
2 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.StringTokenizer; | ||
|
||
public class Main { | ||
public static void main(String[] args) throws IOException { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
|
||
StringTokenizer st = new StringTokenizer(br.readLine()); | ||
int nowYear = Integer.parseInt(st.nextToken()); | ||
int nowMonth = Integer.parseInt(st.nextToken()); | ||
int nowDay = Integer.parseInt(st.nextToken()); | ||
|
||
st = new StringTokenizer(br.readLine()); | ||
int endYear = Integer.parseInt(st.nextToken()); | ||
int endMonth = Integer.parseInt(st.nextToken()); | ||
int endDay = Integer.parseInt(st.nextToken()); | ||
|
||
if (nowYear + 1000 < endYear || nowYear + 1000 == endYear && (nowMonth < endMonth || nowMonth == endMonth && nowDay <= endDay)) { | ||
System.out.println("gg"); | ||
} else { | ||
int day = convertDateToInt(endYear, endMonth, endDay) - convertDateToInt(nowYear, nowMonth, nowDay); | ||
System.out.printf("D-%d", day); | ||
} | ||
} | ||
|
||
private static int convertDateToInt(int year, int month, int day) { | ||
int[] daysOfMonth = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; | ||
int res = 0; | ||
|
||
for (int i = 1; i < year; ++i) | ||
res += (365 + checkLeapYear(i)); | ||
for (int i = 1; i < month; ++i) { | ||
res += daysOfMonth[i]; | ||
if (i == 2) res += checkLeapYear(year); | ||
} | ||
return res + day; | ||
} | ||
private static int checkLeapYear(int year) { | ||
return ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) ? 1 : 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# [Silver V] D-Day - 1308 | ||
|
||
[문제 링크](https://www.acmicpc.net/problem/1308) | ||
|
||
### 성능 요약 | ||
|
||
메모리: 14392 KB, 시간: 128 ms | ||
|
||
### 분류 | ||
|
||
구현 | ||
|
||
### 제출 일자 | ||
|
||
2024년 3월 13일 09:37:39 | ||
|
||
### 문제 설명 | ||
|
||
<p>캠프에 오게 된 송유진은 캠프가 너무 지루해서 오늘로부터 캠프가 끝날 때 까지 며칠이나 남았는지 알아보고 싶었다. 그런데 캠프는 비상식적으로 길지도 몰라서 (윤년을 포함할지도 모른다) 손으로 하나하나 세기에는 힘들어 보였다.</p> | ||
|
||
<p>더욱 정확한 계산을 위해, 유진이는 윤년이 정해지는 기준을 찾아보았고, 그것은 다음과 같았다.</p> | ||
|
||
<ul> | ||
<li>서력기원 연수가 4로 나누어떨어지는 해는 우선 윤년으로 한다. (2004년, 2008년, …)</li> | ||
<li>100으로 나누어떨어지는 해는 평년으로 한다. (2100년, 2200년, …)</li> | ||
<li>400으로 나누어떨어지는 해는 다시 윤년으로 한다. (1600년, 2000년, …)</li> | ||
</ul> | ||
|
||
<p>그런데 캠프가 너무 길 경우, 사춘기인 유진이는 캠프에 무단으로 빠질지도 모른다.</p> | ||
|
||
### 입력 | ||
|
||
<p>첫째 줄에 오늘의 날짜가 주어지고, 두 번째 줄에 D-Day인 날의 날짜가 주어진다. 날짜는 연도, 월, 일순으로 주어지며, 공백으로 구분한다. 입력 범위는 1년 1월 1일부터 9999년 12월 31일 까지 이다. 오늘의 날짜는 항상 D-Day보다 앞에 있다.</p> | ||
|
||
### 출력 | ||
|
||
<p>오늘부터 D-Day까지 x일이 남았다면, "D-"를 출력하고 그 뒤에 공백 없이 x를 출력한다. 만약 캠프가 천년 이상 지속된다면 (오늘이 y년 m월 d일이고, D-Day가 y+1000년 m월 d일과 같거나 늦다면) 대신 "gg"를 출력한다. 오늘이 2월 29일인 경우는 주어지지 않는다.</p> | ||
|