프로그래밍/코드업 일기

코드업(Codeup) 1805 : 입체기동장치 생산공장

Jaebins 2023. 8. 10. 14:03
반응형
import java.util.Scanner;

public class Main {
    static class Instruction{
        int num;
        int gas;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int cnt = sc.nextInt();
        Instruction[] insts = new Instruction[cnt];

        for(int i = 0; i < cnt; i++){
            Instruction inst = new Instruction();
            inst.num = sc.nextInt();
            inst.gas = sc.nextInt();
            insts[i] = inst;
        }

        for(int i = 0; i < cnt; i++){
            for(int j = i; j < cnt; j++){
                if(insts[i].num > insts[j].num){
                    Instruction temp = insts[i];
                    insts[i] = insts[j];
                    insts[j] = temp;
                }
            }
        }

        for(int i = 0; i < cnt; i++) {
            System.out.printf("%d %d\n", insts[i].num, insts[i].gas);
        }
    }

}
반응형