๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Coding Test/Algorithms

[Baekjoon] 2750. ์ˆ˜ ์ •๋ ฌํ•˜๊ธฐ/Java - Bronze2

by The Future Engineer, Lucy 2024. 9. 28.
728x90
๋ฐ˜์‘ํ˜•

โ“๋ฌธ์ œ

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

๐Ÿ“Œ์œ ํ˜•

์ •๋ ฌ

โœ๐Ÿปํ’€์ด

0์—์„œ๋ถ€ํ„ฐ n-1๊นŒ์ง€ ๋ฐ˜๋ณต๋ฌธ ์ˆ˜ํ–‰.
i+1์—์„œ๋ถ€ํ„ฐ n-1๊นŒ์ง€ ๋ฐ˜๋ณต๋ฌธ์„ ์ˆ˜ํ–‰ํ•˜๋ฉด์„œ i์™€ i+1์„ ๋น„๊ตํ•˜๋ฉฐ ์ •๋ ฌ.

๐Ÿ’ป์ฝ”๋“œ

import java.util.*;

public class Main {

    static int n;

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        n = sc.nextInt();
        int[] a = new int[n];

        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }

        for (int i = 0; i < n; i++) {
            for (int j = i+1; j < n; j++){
                if (a[i] > a[j]){
                    int temp = a[i];
                    a[i] = a[j];
                    a[j] = temp;
                }
            }
        }

        for (int i = 0; i < n; i++) {
            System.out.println(a[i]);
        }
    }
}

 

728x90
๋ฐ˜์‘ํ˜•