알고리즘/백준 문제풀이
[C/C++]백준 2752번 - 세수정렬
ya_ya
2021. 10. 18. 22:33
반응형
문제 링크 : https://www.acmicpc.net/problem/2752
2752번: 세수정렬
숫자 세 개가 주어진다. 이 숫자는 1보다 크거나 같고, 1,000,000보다 작거나 같다. 이 숫자는 모두 다르다.
www.acmicpc.net
접근방식
입력이 3개 밖에 없어서 간단하게 버블 정렬을 이용.
코드
#include<iostream>
using namespace std;
int arr[3];
void bubbleSort() {
int tmp;
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 3; j++) {
if (arr[i] > arr[j]) {
tmp = arr[j];
arr[j] = arr[i];
arr[i] = tmp;
}
}
}
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
for (int i = 0; i < 3; i++)
cin >> arr[i];
bubbleSort();
for (int i = 0; i < 3; i++)
cout << arr[i] << ' ';
return 0;
}
다른 문제의 코드 : https://github.com/DaeeYong/Algorithm-Solution-
DaeeYong/Algorithm-Solution-
Solution for Algorithm Problem. Contribute to DaeeYong/Algorithm-Solution- development by creating an account on GitHub.
github.com
반응형