λ°μν
λ¬Έμ
https://www.acmicpc.net/problem/3029
3029λ²: κ²½κ³
첫째 μ€μ νμ¬ μκ°μ΄ hh:mm:ss νμμΌλ‘ μ£Όμ΄μ§λ€. (μ, λΆ, μ΄) hhλ 0λ³΄λ€ ν¬κ±°λ κ°κ³ , 23λ³΄λ€ μκ±°λ κ°μΌλ©°, λΆκ³Ό μ΄λ 0λ³΄λ€ ν¬κ±°λ κ°κ³ , 59λ³΄λ€ μκ±°λ κ°λ€. λμ§Έ μ€μλ λνΈλ₯¨μ λμ§ μκ°
www.acmicpc.net
νμ΄
λκ° λ§μ₯λ νλ λ¬Έμ κ°λ€... -.-
"μ μ΄λ 1μ΄λ₯Ό κΈ°λ€λ¦°λ€"κ° ν¬μΈνΈμλ λ¬Έμ μ΄λ€.
package algorithm;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public String calculateTimeDifference(String currentTime, String bomb) {
int ctHours = Integer.parseInt(currentTime.substring(0, 2));
int ctMinutes = Integer.parseInt(currentTime.substring(3, 5));
int ctSeconds = Integer.parseInt(currentTime.substring(6, 8));
int bHours = Integer.parseInt(bomb.substring(0, 2));
int bMinutes = Integer.parseInt(bomb.substring(3, 5));
int bSeconds = Integer.parseInt(bomb.substring(6, 8));
int secondsDiff = (bSeconds - ctSeconds + 60) % 60;
if (bSeconds - ctSeconds < 0) {
bMinutes--;
}
int minutesDiff = (bMinutes - ctMinutes + 60) % 60;
if (bMinutes - ctMinutes < 0) {
bHours--;
}
int hoursDiff = (bHours - ctHours + 24) % 24;
String timeFormat = String.format("%02d:%02d:%02d", hoursDiff, minutesDiff, secondsDiff);
if (hoursDiff == 0 && minutesDiff == 0 && secondsDiff == 0) {
timeFormat = "24:00:00";
}
return timeFormat;
}
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String currentTime = br.readLine();
String bomb = br.readLine();
Main m = new Main();
String answer = m.calculateTimeDifference(currentTime, bomb);
System.out.println(answer);
}
}
μ λ΅
λ°μν
'π°ππππππππ > π±πππππππ' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
[λ°±μ€/Java] ν 2 18258 (0) | 2023.11.15 |
---|---|
[λ°±μ€/Java] μ°½μλ§μ 3028 (0) | 2023.11.13 |
[λ°±μ€/Java] ν΄λ¦¬μ€λ―Έλ Έ 1343 (0) | 2023.11.10 |
[λ°±μ€/Java] λ‘ν 2217 (1) | 2023.11.09 |
[λ°±μ€/Java] μλ°μ κ°νΈ 1758 (0) | 2023.11.08 |