728x90

😢 단순 비교도 가능하지만, 정렬로 쉽게 풀 수 있는 문제
😊 각종 정렬을 이용해 풀 수 있음(여기선 선택정렬 selection sort)
This file contains hidden or 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 <bits/stdc++.h> | |
using namespace std; | |
int main(void) { | |
ios::sync_with_stdio(false), cin.tie(nullptr); | |
int a, b, c; | |
cin >> a >> b >> c; | |
int d, e, f; | |
d = min({a, b, c}); | |
f = max({a, b, c}); | |
e = a + b + c - d - f; | |
cout << d << ' ' << e << ' ' << f; | |
} | |
/* | |
#include <bits/stdc++.h> | |
using namespace std; | |
int main(void) { | |
ios::sync_with_stdio(false), cin.tie(nullptr); | |
int arr[4]; | |
for (int i = 0; i < 3; i++) cin >> arr[i]; | |
sort(arr, arr + 3); | |
for (int i = 0; i < 3; i++) cout << arr[i] << ' '; | |
} | |
*/ | |
/* | |
#include <stdio.h> | |
int arr[3] = {}; | |
void selectionSort(int *arr) { | |
int i, j; | |
int indexOfMin; | |
int lesser; | |
for (i = 0; i < 2; i++) { | |
indexOfMin = i; | |
for (j = i + 1; j < 3; j++) { | |
if (arr[indexOfMin] > arr[j]) { | |
indexOfMin = j; | |
} | |
} | |
if (indexOfMin != i) { | |
lesser = arr[indexOfMin]; | |
arr[indexOfMin] = arr[i]; | |
arr[i] = lesser; | |
} | |
} | |
} | |
void print(int arr[]) { | |
for (int i = 0; i < 3; i++) printf("%d ", arr[i]); | |
} | |
int main(void) { | |
for (int i = 0; i < 3; i++) scanf("%d", &arr[i]); | |
selectionSort(arr); | |
print(arr); | |
return 0; | |
} | |
*/ | |
/* 단순 비교 연산 | |
#include <bits/stdc++.h> | |
using namespace std; | |
int main() { | |
ios::sync_with_stdio(false), cin.tie(nullptr); | |
int a[3] = {}; | |
for (int i = 0; i < 3; i++) { | |
cin >> a[i]; | |
} | |
if (a[0] < a[1] && a[0] < a[2]) { | |
cout << a[0] << " "; | |
if (a[1] < a[2]) { | |
cout << a[1] << " " << a[2]; | |
} else { | |
cout << a[2] << " " << a[1]; | |
} | |
} else if (a[1] < a[0] && a[1] < a[2]) { | |
cout << a[1] << " "; | |
if (a[0] < a[2]) { | |
cout << a[0] << ' ' << a[2]; | |
} else { | |
cout << a[2] << ' ' << a[0]; | |
} | |
} else { | |
cout << a[2] << ' '; | |
if (a[0] < a[1]) { | |
cout << a[0] << ' ' << a[1]; | |
} else { | |
cout << a[1] << ' ' << a[0]; | |
} | |
} | |
} | |
*/ |
'Algorithm > C&C++' 카테고리의 다른 글
백준 2753번: 윤년(c++) (0) | 2021.09.29 |
---|---|
백준 1000번: A+B(c++) (0) | 2021.09.27 |
백준 10871번: X보다 작은 수 c++(cpp) (0) | 2021.09.06 |
백준 10804번: 카드 역배치 c++(cpp) (0) | 2021.09.02 |
백준 2440번: 별 찍기 - 3 c++(cpp) (0) | 2021.09.01 |