![[백준 / BOJ] 2750번 수 정렬하기 (C++, Python)](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FcBaXiH%2FbtrJqp9PTAW%2FtTgaYyTKoIvptSrPuK3wdK%2Fimg.png)
[백준 / BOJ] 2750번 수 정렬하기 (C++, Python)◎ 자료구조와 알고리즘/백준(BOJ) 문제풀이2022. 4. 13. 18:17
Table of Contents
반응형
링크 : https://www.acmicpc.net/problem/2750
2750번: 수 정렬하기
첫째 줄에 수의 개수 N(1 ≤ N ≤ 1,000)이 주어진다. 둘째 줄부터 N개의 줄에는 수 주어진다. 이 수는 절댓값이 1,000보다 작거나 같은 정수이다. 수는 중복되지 않는다.
www.acmicpc.net
문제

문제 풀이
버블 정렬, 삽입 정렬, 선택 정렬 등의 방법으로 풀 수 있는 문제이다. 아래 코드는 버블 정렬로 구현했다. 예전에 구현했던 코드가 있어 약간 수정만 가했다. 아래 링크에서 버블 정렬에 대한 정리를 볼 수 있다.
https://reo91004.tistory.com/120
[기초] 버블 정렬, 선택 정렬, 삽입 정렬에 대하여
정렬 알고리즘 정렬 알고리즘이란 원소들을 일정한 순서대로 열거하는 알고리즘이다. 정렬 알고리즘은 다양한 알고리즘들이 있다. 이번 포스팅에 들어갈 버블 정렬, 선택 정렬, 삽입 정렬 이외
reo91004.tistory.com
C++ 코드 전문
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <algorithm> | |
#include <iostream> | |
#include <vector> | |
using namespace std; | |
void BubbleSort(int arr[], int N) { | |
int i, j; | |
int temp; | |
for (i = 0; i < N - 1; ++i) | |
for (j = i + 1; j < N; j++) { | |
if (arr[i] > arr[j]) { | |
temp = arr[i]; | |
arr[i] = arr[j]; | |
arr[j] = temp; | |
} | |
} | |
} | |
int main() { | |
int N; | |
int* arr; | |
cin >> N; | |
if (N < 1 || N > 1000) | |
exit(1); | |
arr = new int[N]; | |
for (int i = 0; i < N; ++i) | |
cin >> arr[i]; | |
BubbleSort(arr, N); | |
for (int i = 0; i < N; ++i) | |
cout << arr[i] << "\n"; | |
delete arr; | |
return 0; | |
} |
Python 코드 전문
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
N = int(input()) | |
arr = [] | |
for i in range(N) : | |
arr.append(int(input())) | |
arr.sort() | |
for i in range(len(arr)) : | |
print(arr[i]) |
소감
반응형
'◎ 자료구조와 알고리즘 > 백준(BOJ) 문제풀이' 카테고리의 다른 글
[백준 / BOJ] 10989번 수 정렬하기 3 (C++, Python) (0) | 2022.04.14 |
---|---|
[백준 / BOJ] 2751번 수 정렬하기 2 (C++, Python) (0) | 2022.04.14 |
[백준 / BOJ] 1436번 영화감독 숌 (C++, Python) (0) | 2022.04.13 |
[백준 / BOJ] 1018번 체스판 다시 칠하기 (C++, Python) (0) | 2022.04.13 |
[백준 / BOJ] 7568번 덩치 (C++, Python) (0) | 2022.04.12 |
@Reo :: 코드 아카이브
자기계발 블로그