algorithm codes/baekjoon online judge

2750번: 수 정렬하기 (백준 온라인 저지, C++)

mimizzang 2019. 4. 1. 01:30

문제 해설

 

 단순한 정렬 문제입니다. 버블 소트를 활용하여 풀이하였습니다.

 

 

코드

 

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
31
#include <iostream>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 
    int n;
    int d[1000];
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> d[i];
 
    //bubble sort
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n - i - 1; j++)
        {
            if (d[j] > d[j + 1])
            {
                int tmp = d[j];
                d[j] = d[j + 1];
                d[j + 1= tmp;
            }
        }
    }
 
    for (int i = 0; i < n; i++)
        cout << d[i] << '\n';
 
}
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5; text-decoration:none">Colored by Color Scripter

 

 

제출 결과

 

 

 

문제 출처

 

https://www.acmicpc.net/problem/2750

 

2750번: 수 정렬하기

첫째 줄에 수의 개수 N(1 ≤ N ≤ 1,000)이 주어진다. 둘째 줄부터 N개의 줄에는 숫자가 주어진다. 이 수는 절댓값이 1,000보다 작거나 같은 정수이다. 수는 중복되지 않는다.

www.acmicpc.net