본문 바로가기
PROGRAMMING/[java] Baekjoon Online Judge (BOJ)

[java/BOJ] sw코딩멘토링 - 2480, 2884, 10813

by J_Kkikki 2026. 3. 31.

1. 2480번 : 주사위 세 개

https://www.acmicpc.net/problem/2480

import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int a = s.nextInt();
        int b = s.nextInt();
        int c = s.nextInt();
        int res = 0;
        
        if(a == b && b == c) { //3개가 같음
            res = 10000 + a*1000;
        }
        else { 
            if(a==b) {
                res = 1000 + a*100;
            }
            else if(b==c) {
                res = 1000 + b*100;
            }
            else if(c==a) {
                res = 1000 + c*100;
            }
            else { //모두 다름
                //최대 수를 찾아야됨
                int max = (a>b) ? ((a>c)?a:c) : ((b>c)?b:c);
                res = max*100;
            }
        }
        
        System.out.println(res);
        s.close();
    }
}

 

2. 2884번 : 알람 시계

https://www.acmicpc.net/problem/2884

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        
        int h = s.nextInt();
        int m = s.nextInt();
        
        int chgm = h*60 + m; //분으로 다 바꿈
        chgm -= 45; //45분을 뺀다
        
        if(chgm < 0 ){
            chgm += 60*24;
        }
        
        System.out.println(chgm/60+" "+chgm%60);
        
        s.close();
    }
}

 

3. 10813번 : 공 바꾸기

https://www.acmicpc.net/problem/10813

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt(); //바구니 
        int m = s.nextInt(); //바꾸는 횟수
        int[] ary = new int[n+1];
        
        //공 넣기(초기상태 설정)
        for(int i = 1; i<=n; i++) {
            ary[i] = i;
        }
        
        //바꾸기 실행
        for(int i = 1; i<=m; i++) {
            int dummy = 0;
            int a = s.nextInt();
            int b = s.nextInt();
            dummy = ary[a];
            ary[a] = ary[b];
            ary[b] = dummy;
        }
        
        for(int i = 1; i<=n; i++) {
            System.out.print(ary[i]+" ");
        }
        
        s.close();
    }
}