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
๋ฐ์ํ
'Coding Test > Algorithms' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Baekjoon] 15649.N๊ณผ M (1)/Java - Silver3 (0) | 2024.09.29 |
---|---|
[ํ๋ก๊ทธ๋๋จธ์ค] ์ฃผ์๊ฐ๊ฒฉ/Java - Lv.2 (0) | 2024.09.29 |
[Baekjoon] 28278. ์คํ 2/Java - Silver4 (0) | 2024.09.28 |
[ํ๋ก๊ทธ๋๋จธ์ค] ์์/Python - Lv.3 (1) | 2024.09.28 |
[Baekjoon] 1546. ํ๊ท /Java - Bronze1 (1) | 2024.09.28 |