```
백준 6812번 Good times JAVA 구현해보기
```

이번 글을 통해 배워갈 내용
- 백준 6812번 풀이
https://www.acmicpc.net/problem/6812
6812번: Good times
A mobile cell service provider in Ottawa broadcasts an automated time standard to its mobile users that reflects the local time at the user’s actual location in Canada. This ensures that text messages have a valid local time attached to them. For example
www.acmicpc.net
백준 6812번 Good times는
난이도 브론즈 등급의 문제로서
오타와의 시간이 주어질 때 나머지 캐나다 주의 시간을 구해주면 되는 문제입니다.
24시간 기준이며
24시는 0시로 표현
분은 00분 부터 59분 사이로 표현해주면 됩니다.
30분 정도 위에 링크를 방문하셔서 풀어보시고
안 풀리시는 경우에만 아래 해답을 봐주시면 감사하겠습니다.
각 시간을 계산 후 출력해주었습니다.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException {
final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int timeInOttawa = Integer.parseInt(br.readLine());
System.out.println(timeInOttawa + " in Ottawa");
System.out.println(adjustTime(timeInOttawa - 300) + " in Victoria");
System.out.println(adjustTime(timeInOttawa - 200) + " in Edmonton");
System.out.println(adjustTime(timeInOttawa - 100) + " in Winnipeg");
System.out.println(timeInOttawa + " in Toronto");
System.out.println(adjustTime(timeInOttawa + 100) + " in Halifax");
System.out.println(adjustTime(timeInOttawa + 130) + " in St. John's");
}
private static int adjustTime(int rawTime) {
int curTime = rawTime;
// 분이 60분 보다 크다면
if (curTime % 100 > 59) {
curTime += 100;
curTime -= 60;
}
// 분이 60분 보다 작다면
if (curTime % 100 < -59) {
curTime -= 100;
curTime += 60;
}
// 시간이 음수인 경우
if (rawTime < 0) {
curTime = 2400 + rawTime;
}
// 시간이 24시간보다 크거나 같은 경우
if (curTime > 2399) {
curTime %= 2400;
}
return curTime;
}
}
읽어주셔서 감사합니다
무엇인가 얻어가셨기를 바라며
오늘도 즐거운 코딩 하시길 바랍니다 ~ :)
728x90
'Java > Java 알고리즘' 카테고리의 다른 글
| 백준 1681번 줄세우기 JAVA 구현해보기 (0) | 2022.01.31 |
|---|---|
| 백준 10162번 전자레인지 JAVA 구현해보기 (0) | 2022.01.31 |
| 백준 6811번 Old Fishin’ Hole JAVA 구현해보기 (0) | 2022.01.31 |
| 백준 1759번 암호 만들기 JAVA 구현해보기 (0) | 2022.01.31 |
| 백준 1837번 암호제작 JAVA 구현해보기 (0) | 2022.01.31 |