알고리즘(백준 등) 공부
SWEA 12368. 24시간
posite
2026. 5. 22. 11:40
하루를 0시부터 23시까지로 표현할 때, 시작시간 a에서 b시간이 지난 시간을 출력하는 문제이다.
a + b 를 24로 나눈 나머지가 현재 시간이 된다.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int T = Integer.parseInt(br.readLine());
StringBuilder sb = new StringBuilder();
for(int tc=1; tc<=T; tc++) {
sb.append('#').append(tc).append(' ');
StringTokenizer st = new StringTokenizer(br.readLine());
int a = Integer.parseInt(st.nextToken()), b = Integer.parseInt(st.nextToken());
int result = (a + b) % 24;
sb.append(result).append('\n');
}
br.close();
System.out.print(sb);
}
}