SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
시간문제는 초로 합쳐서 계산해주기
import java.util.Scanner;
import java.io.FileInputStream;
class Solution
{
public static void main(String args[]) throws Exception
{
Scanner sc = new Scanner(System.in);
int T;
T=sc.nextInt();
sc.nextLine();
for(int test_case = 1; test_case <= T; test_case++)
{
String[] first=sc.nextLine().split(":");
String[] sec=sc.nextLine().split(":");
int first_h=Integer.parseInt(first[0])*3600+Integer.parseInt(first[1])*60+Integer.parseInt(first[2]);
int sec_h=Integer.parseInt(sec[0])*3600+Integer.parseInt(sec[1])*60+Integer.parseInt(sec[2]);
if(sec_h-first_h<0){
sec_h+=24*3600;
}
int result=sec_h-first_h;
int hour=result/3600;
int min=(result-hour*3600)/60;
int se=(result-hour*3600-min*60);
String hour1=String.valueOf(hour);
String min1=String.valueOf(min);
String sec1=String.valueOf(se);
if(hour<10){
hour1="0"+hour1;
}
if(min<10){
min1="0"+min1;
}
if(se<10){
sec1="0"+sec1;
}
System.out.println("#"+test_case+" "+hour1+":"+min1+":"+sec1);
}
}
}
'알고리즘 > 삼성 SW expert Academy' 카테고리의 다른 글
[SWEA] 7985. Rooted Binary Tree 재구성_JAVA (0) | 2022.05.26 |
---|---|
[SWEA] 8104. 조 만들기_JAVA (0) | 2022.05.26 |
[SWEA] 8338. 계산기_JAVA (0) | 2022.05.25 |
[SWEA] 8457. 알 덴테 스파게티_JAVA (0) | 2022.05.25 |
[SWEA] 8673. 코딩 토너먼트1_JAVA (0) | 2022.05.24 |