BEAKJOON
백준(2751번 수 정렬하기 2)풀이 C++
Shin_jisoo
2021. 1. 17. 23:25
728x90
2751번: 수 정렬하기 2
첫째 줄에 수의 개수 N(1 ≤ N ≤ 1,000,000)이 주어진다. 둘째 줄부터 N개의 줄에는 숫자가 주어진다. 이 수는 절댓값이 1,000,000보다 작거나 같은 정수이다. 수는 중복되지 않는다.
www.acmicpc.net
1) 주석 없는 VERSION
#include <iostream>
#include <cmath>
#include <stdio.h>
#include <utility>
#include <string>
#include <algorithm>
using namespace std;
int main() {
int n;
cin >> n;
int array[1000000] = { 0, };
for (int i = 0;i < n;i++) {
cin >> array[i];
}
sort(array, array + n);
for (int i = 0;i < n;i++) {
cout << array[i] << "\n";
}
}
2) 주석 있는 VERSION
#include <iostream>
#include <cmath>
#include <stdio.h>
#include <utility>
#include <string>
//sort 사용하기 위해서는 필요
#include <algorithm>
using namespace std;
int main() {
int n; // 입력받을 수의 개수
cin >> n;
int array[1000000] = { 0, };
//입력
for (int i = 0;i < n;i++) {
cin >> array[i];
}
// 처음부터, array의 끝자리까지 오름차순 정렬
sort(array, array + n);
for (int i = 0;i < n;i++) {
cout << array[i] << "\n";
}
}