๐Ÿ•ธ Algorithm/๐Ÿ•ธ ๋ฐฑ์ค€ BaekJoon

[๋ฐฑ์ค€][java][2525][์˜ค๋ธ ์‹œ๊ณ„]

๋‰ด์ด NUEY 2023. 9. 30. 16:19
๋ฐ˜์‘ํ˜•

import java.util.Scanner;

public class Main {

	public static void main(String[] agrs) {
		Scanner sc = new Scanner(System.in);
		
		int hour = sc.nextInt();
		int min = sc.nextInt();
		int time = sc.nextInt();
		int total = hour*60 + min + time;
		int printHour = total / 60;
		int printMin = total % 60;
		
		if (printHour >= 24) printHour -= 24; 
		
		System.out.printf("%d %d", printHour, printMin);		
	}
}
  • ์ž…๋ ฅ๋œ ์‹œ hour * 60๋ถ„ + ์ž…๋ ฅ๋œ ๋ถ„min + ์กฐ๋ฆฌ์‹œ๊ฐ„ time(๋ช‡ ๋ถ„ ๊ฑธ๋ฆฌ๋Š” ์ง€..)์„ ๋ชจ๋‘ ๋”ํ•ฉ๋‹ˆ๋‹ค.
  • ๋ชจ๋‘ ๋ถ„์œผ๋กœ ๊ณ„์‚ฐ๋œ ๊ฐ’์„ total์— ๋‹ด์•„ ์ถœ๋ ฅํ•  ์‹œprintHour๋Š” / ๋‚˜๋ˆ„๋ฉด ์ •์ˆ˜int์ด๊ธฐ๋•Œ๋ฌธ์— ์‹œ๋งŒ ๋‚ฉ์Šต๋‹ˆ๋‹ค.
  • total์„ % ํผ์„ผํŠธ๋กœ ๊ณ„์‚ฐํ•˜๋ฉด ๋‚˜๋จธ์ง€๊ฐ’๋งŒ ๋‚จ์Šต๋‹ˆ๋‹ค.
    ex) 130 % 60 ํ•˜๋ฉด 10์ด ๋‚จ์Šต๋‹ˆ๋‹ค.
  • ๋ฌธ์ œ์—์„œ ์ถœ๋ ฅ์— 0์—์„œ 23๊นŒ์ง€๋งŒ ์ •์ˆ˜๋ผ๋Š” ์กฐ๊ฑด์ด ์žˆ๊ธฐ์— 24์‹œ ์ด์ƒ์€ -24๋ฅผ ํ•ด์ค๋‹ˆ๋‹ค.
    ex) 26 - 24 = 2, 24 - 24 = 0. ์ด๋Ÿฐ์‹์œผ๋กœ ํ‘œ๊ธฐ๋˜๊ฒ ์ฃ ..

 

 

๋ฐ˜์‘ํ˜•