๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿ’ป ์ฝ”๋”ฉํ…Œ์ŠคํŠธ/๋ฐฑ์ค€

[๋ฐฑ์ค€/Java] ๋‹จ๊ณ„๋ณ„๋กœ ํ’€๊ธฐ 2๋‹จ๊ณ„ ์กฐ๊ฑด๋ฌธ (2884 ์•Œ๋žŒ ์‹œ๊ณ„ , 2525 ์˜ค๋ธ ์‹œ๊ณ„, 2480 ์ฃผ์‚ฌ์œ„ ์„ธ๊ฐœ) ๋ชจ์Œ

by ๋ฝ€์งœ๊ผฌ 2025. 1. 17.
728x90
๋ฐ˜์‘ํ˜•

๋ฐฑ์ค€

 

๋ฐฑ์ค€ 2๋‹จ๊ณ„ ์กฐ๊ฑด๋ฌธ ํ’€์ด ๋ชจ์Œ.

์œค๋…„์€ ๋”ฐ๋กœ ํฌ์ŠคํŒ… ์˜ฌ๋ ค๋†“์•˜๋‹ค.


๐Ÿ“ 2884 ์•Œ๋žŒ์‹œ๊ณ„ (196ms)

import java.io.IOException;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws IOException {
        Scanner scanner = new Scanner(System.in);
        int H = scanner.nextInt();
        int M = scanner.nextInt();

        if ( H > 0 ) {
            if ( M >= 45) {
                M = M - 45;
                System.out.println(H +" "+ M);
            } else if ( M < 45) {
                H = H - 1;
                M = M + 15;
                System.out.println(H +" "+ M);
            }   
        } else if ( H == 0 ) {
            if ( M >= 45) {
                M = M - 45;
                System.out.println(H +" "+ M);
            } else if ( M < 45) {
                H = 23;
                M = M + 15;
                System.out.println(H +" "+ M);
            }
        }
    }
}

 

๐Ÿ“ 2525 ์˜ค๋ธ์‹œ๊ณ„ (148ms)

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        StringTokenizer st = new StringTokenizer(br.readLine());
        int A = Integer.parseInt(st.nextToken());
        int B = Integer.parseInt(st.nextToken());
        int C = Integer.parseInt(br.readLine());

        int h = (B + C)/60;
        int m = (B + C)%60;

        int fh = A + h;

        if (fh > 23){
            System.out.println(fh-24 +" "+ m);
        } else {
            System.out.println(fh+" "+ m);
        }
    }
}

 

๐Ÿ’ญํ’€์ด

60๋ถ„ == 1์‹œ๊ฐ„

๊ทธ๋Ÿฌ๋ฉด ๋ถ„(B,C)์„ ๋ชจ๋‘ ๋”ํ•ด์„œ 60๋ถ„์œผ๋กœ ๋‚˜๋ˆˆ ๋ชซ๊ณผ ๋‚˜๋จธ์ง€๋ฅผ ์ด์šฉํ•˜์ž

๋งŒ์•ฝ์— 23์‹œ๋ฅผ ๋„˜์–ด๋ฒ„๋ฆฌ๋ฉด 0์œผ๋กœ ๋ณ€๊ฒฝํ•˜์ž (24๋นผ๊ธฐ)

 

๐Ÿ“ 2480 ์ฃผ์‚ฌ์œ„ ์„ธ๊ฐœ (104ms)

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());

        int n1 = Integer.parseInt(st.nextToken());
        int n2 = Integer.parseInt(st.nextToken());
        int n3 = Integer.parseInt(st.nextToken());
        int max = n1;

        if (n1 == n2 && n1 == n3) {
            System.out.println(10000 + n1*1000);
        } else if (n1 == n2 || n1 == n3) {
            System.out.println(1000 + n1*100);
        } else if (n2 == n3) {
            System.out.println(1000 + n2*100);
        } else {
            if(max <= n2){
                max = n2;
                if(max <= n3){
                    max = n3;
                }
            } else {
              if(max <= n3){
                  max = n3;
              }
            }
            System.out.println(max*100);
        }
    }
}

๐Ÿ’ญํ’€์ด

์ด๋ฏธ ์œ„์˜ if์—์„œ ๊ฑธ๋Ÿฌ์ง„ ์กฐ๊ฑด์€ else if์— ์•ˆ์ ์–ด๋„ ๋œ๋‹ค.

n2 == n3 ์กฐ๊ฑด์„ ์•ˆ๋„ฃ์–ด๋„ ๋˜๋Š” ์ด์œ .

728x90
๋ฐ˜์‘ํ˜•