SWEA
[SWEA] 숫자를 정렬하자
itsnot4me
2024. 9. 30. 15:12
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
import java.util.Scanner;
import java.io.FileInputStream;
class Solution
{
public static void main(String args[]) throws Exception
{
Scanner sc = new Scanner(System.in);
int T;
T=sc.nextInt();
for(int test_case = 1; test_case <= T; test_case++)
{
int a = sc.nextInt();
int[] array =new int[a];
for(int i=0; i<a; i++){
array[i] = sc.nextInt();
}
for(int k=0; k<a-1; k++){
for(int j=0; j<a-1; j++){
int temp =0;
if(array[j]>array[j+1]){
temp = array[j];
array[j]=array[j+1];
array[j+1]=temp;
}
}
}
System.out.print("#" + test_case + " ");
for(int l=0; l<a; l++){
System.out.print(array[l]+ " ");
}
System.out.println();
}
}
}
sort를 쓰면 쉽겠지만 문제의 의도가 그게 아니겠다는 생각에..
배열에 숫자 받아서 버블 정렬로 오름차순으로 정렬.