본문 바로가기
1일 1알고/알고리즘 재활 프로젝트

SWEA 1976. 시각 덧셈 (Java)

by yeong. 2021. 12. 6.

문제 4개 오늘도 완료!

 

package week2;

import java.util.Scanner;

public class Solution_시각덧셈 {
	
	static int TC;
	
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		TC=sc.nextInt();
		
		for(int tc=1; tc<=TC; tc++) {
			int h1=sc.nextInt();
			int m1=sc.nextInt();
			int h2=sc.nextInt();
			int m2=sc.nextInt();
			
			int h=h1+h2;
			int m=m1+m2;
			
			while(true) {
				if(h>=1 && h<=12 && m>=0 && m<=59) break;
				
				if(m>=60) {
					m-=60;
					h++;
				}
				if(h>=13) {
					h-=12;
				}
			}

			System.out.println("#"+tc+" "+h+" "+m);
		}// end tc
		
	}

}