NO.2525
풀이코드
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int h = sc.nextInt();
int m = sc.nextInt();
int c = sc.nextInt();
sc.close();
if (m+c>=60) {
h = h + (m+c)/60;
m = (m+c)%60;
if (h>23) {
h = h-24;
}
System.out.println(h + " " + m);
}
else {
System.out.println(h + " " + (m+c));
}
}
}
📌생각보다 일찍 틀린 문제가 나와서 속상.. 너무 단순하게 생각했나보다.
틀렸다고 바로 답 찾아보는거보단 혼자 고민해보는걸 좋아해서 이런 저런 방법들로 다시 풀어보고
잘 풀어내면 그때 글 수정해놓겠습니닷,,
✨ 수정 완료! 왜 틀렸나 생각해봤더니 h가 23보다 커지면, h에서 24시를 빼야하는데, 난 반대로 적어놨었네.. 이런 멍충이ㅠㅠㅠ 다른 숫자로 출력시켜보니 -1시가 뜨길래 눈치챘다ㅠㅠ 진짜 단순한 숫자계산에서 틀리니 부끄럽기도하고 이걸 바로 못알아차린게 어이없기도 한데, 이렇게 기록해놔야 같은 실수 반복 안하겠지 쥬륵..🤣
더보기
(내가 적은 오답코드)
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int h = sc.nextInt();
int m = sc.nextInt();
int c = sc.nextInt();
sc.close();
if (m+c>=60) {
h = h + (m+c)/60;
m = (m+c)%60;
if (h>23) {
h = 24-h;
}
System.out.println(h + " " + m);
}
else {
System.out.println(h + " " + (m+c));
}
}
}
'JAVA-BAEKJOON > 2단계 조건문' 카테고리의 다른 글
[백준/02-07] 2480 주사위 세 개 (0) | 2024.02.21 |
---|---|
[백준/02-05] 2884 알람 시계 (0) | 2024.02.19 |
[백준/02-04] 14681 사분면 고르기 (0) | 2024.02.19 |
[백준/02-03] 2753 윤년 (0) | 2024.02.18 |
[백준/02-02] 9498 시험 성적 (0) | 2024.02.18 |