본문 바로가기

Java/SWEA

[JAVA] SWEA 1976. 시각 덧셈

https://swexpertacademy.com/main/solvingProblem/solvingProblem.do

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com

 

 

정답 

 

import java.util.Scanner;

class Solution
{
	public static void main(String args[]) throws Exception
	{	
		Scanner sc = new Scanner(System.in);
		
		int T = sc.nextInt();
		
		for(int t=1; t<=T; t++)
		{
			int t1 = sc.nextInt();
			int m1 = sc.nextInt();
			int t2 = sc.nextInt();
			int m2 = sc.nextInt();
			
			int sum = ((t1*60)+m1)+((t2*60)+m2);
			
			int ans_t=0;
			int ans_n=0;
			
			if(sum/60>12)
			{
				ans_t = sum/60-12;
			}
			else
			{
				ans_t = sum/60;
			}
			
			ans_n = sum%60;
			
			System.out.printf("#%d %d %d\n", t,ans_t,ans_n);
				
		}
	}
}