알고리즘 풀이/백준
[백준][Java] 2750번 수 정렬하기
배게
2018. 4. 21. 00:20
728x90
가장 큰 값을 뒤로 보내는 정렬
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int num = sc.nextInt(); int temp; int[] res = new int[num]; for(int i=0; i<num; i++) { res[i] = sc.nextInt(); } for(int i=0; i<res.length; i++) { for(int j=0;j<res.length-1-i;j++) { if(res[j]>res[j+1]) { temp=res[j]; res[j]=res[j+1]; res[j+1]=temp; } } } for (int i : res) { System.out.println(i); } } } |