Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Tags
- 코테
- 패캠
- 프로그래머스
- 코딩자격증
- 수정렬하기3
- fastcampus
- intelij
- 배열
- 스프링부트시작
- 알고리즘
- 패스트캠퍼스후기
- springboot
- 자바
- 파이썬
- 개발포트폴리오
- 10989
- 소금폭탄
- sql문법
- DockerDesktop
- SQL
- 3273
- 백준
- 자바스크립트
- 코딩테스트
- 노션
- java
- 패스트캠퍼스
- 코딩교육
- java11
- BOJ
Archives
- Today
- Total
기록용 블로그
[boj13223] 소금폭탄 본문
https://www.acmicpc.net/problem/13223
13223번: 소금 폭탄
첫째 줄에는 현재 시각이 hh:mm:ss로 주어진다. 시간의 경우 0≤h≤23 이며, 분과 초는 각각 0≤m≤59, 0≤s≤59 이다. 두 번째 줄에는 소금 투하의 시간이 hh:mm:ss로 주어진다.
www.acmicpc.net
1. 계층적으로 표현되는 각 단위를 계산할 때,
가장 작은 단위로 통일하면 더 편할 수 있다.
//모두 초로 변환
int n_date = Integer.parseInt(n_date_array[0]) * 60 * 60
+ Integer.parseInt(n_date_array[1]) * 60
+ Integer.parseInt(n_date_array[2]);
int s_date = Integer.parseInt(s_date_array[0]) * 60 * 60
+ Integer.parseInt(s_date_array[1]) * 60
+ Integer.parseInt(s_date_array[2]);
int out_date = s_date - n_date;
if(out_date <= 0) out_date += 24 * 3600; //하루가 이미 지남
// 10000초 = 3600 * (2시간) + 2800초
// = 2시간 + 60 * (46분) + 40초
// = 2시간 46분 40초
int out_date_h = out_date / 3600;
int out_date_m = (out_date%3600) / 60;
int out_date_s = out_date%60;
2. 문자열 포맷코드
| 코드 | 설명 |
| %s | 문자열 (String) |
| %c | 문자 1개 (character) |
| %d | 정수 (Integer) |
| %f | 부동소수 (floating-point) |
| %o | 8진수 |
| %x | 16진수 |
| %% | Literal % (문자 % 자체) |
//표현방식 2가지
//(HH:MM:SS)
//1. String.format 사용
//String ans = String.format("%02d:%02d:%02d", out_date_h, out_date_m, out_date_s);
//System.out.println(ans)
//2.printf 사용
System.out.printf("%02d:%02d:%02d", out_date_h, out_date_m, out_date_s);'개발 > 알고리즘 공부' 카테고리의 다른 글
| [알고리즘] 시간복잡도 (0) | 2023.04.20 |
|---|---|
| [프로그래머스][LV1] 덧칠하기 (0) | 2023.04.06 |
| [프로그래머스][LV1] 바탕화면 정리 (0) | 2023.04.06 |
| [프로그래머스][LV1] 공원 산책 (0) | 2023.04.05 |
| [BOJ1919] 애너그램 만들기 (0) | 2023.04.05 |