문제 링크: https://www.acmicpc.net/problem/2525
백준 조건문 6단계 - 2525번 오븐 시계를 풀어보았다.
풀이: 현재시간과 조리시간을 받아 완료시간을 출력하면 된다.
C++
#include <iostream>
using namespace std;
int main()
{
int hour,minute, cook;
cin >> hour>>minute;
cin >> cook; // 조리시간
minute+=cook;
while(minute>=60) // 60분이 넘어가면
{
minute-=60;
hour++;
if(hour>=24) // 24시간이 지나면
{
hour-=24;
}
}
cout<<hour<<" "<<minute;
}
Python
a,b=map(int,input().split())
c=int(input())
b+=c
while(b>=60):
b-=60
a+=1
if(a>=24): a-=24
print(a,b)
Java
import java.util.Scanner;
class Main
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int hour=sc.nextInt();
int minute=sc.nextInt();
int time=sc.nextInt();
minute+=time;
while(minute>=60)
{
minute-=60;
hour++;
if(hour>=24) hour-=24;
}
System.out.println(hour+" "+minute);
}
}
'코테용 문제풀이 > 백준' 카테고리의 다른 글
구구단 풀이 (0) | 2022.12.30 |
---|---|
주사위 세개 풀이 (0) | 2022.12.30 |
알람 시계 풀이 (0) | 2022.12.30 |
사분면 고르기 풀이 (0) | 2022.12.30 |
윤년 풀이 (0) | 2022.12.30 |