[BOJ][2751] 수 정렬하기 2
Updated:
1. 문제 링크
https://www.acmicpc.net/problem/2751
2. 사용 알고리즘
정렬
3. 풀이
STL의 sort, JAVA의 Arrays.sort를 이용하여 입력받은 수 정렬 후 출력
4. 소스 코드
4-1. C++
https://github.com/dev-aiden/problem-solving/blob/main/boj/2751.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
#include <algorithm>
using namespace std;
int arr[1000003];
int main(void) {
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int n; cin >> n;
for (int i = 0; i < n; ++i) cin >> arr[i];
sort(arr, arr + n);
for (int i = 0; i < n; ++i) cout << arr[i] << "\n";
return 0;
}
4-2. JAVA
https://github.com/dev-aiden/problem-solving/blob/main/boj/2751.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
public class Main {
static int arr[] = new int[1000003];
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
for(int i = 0; i < n; ++i) arr[i] = Integer.parseInt(br.readLine());
Arrays.sort(arr, 0, n);
StringBuilder sb = new StringBuilder();
for(int i = 0; i < n; ++i) sb.append(arr[i]).append("\n");
System.out.println(sb);
}
}
Leave a comment