알고리즘 풀이/백준(Boj)
백준(BOJ) 3047번 ABC
100win10
2019. 9. 21. 18:41
문제 : https://www.acmicpc.net/problem/3047
세 수 A, B, C가 주어진다. A는 B보다 작고, B는 C보다 작다.
세 수 A, B, C가 주어졌을 때, 입력에서 주어진 순서대로 출력하는 프로그램을 작성하시오.
풀이 :
숫자들을 오름차순 정렬해서 배열에 저장해두자. 그 후 알파벳 - 'A' 를 통해 배열 인덱스에 접근해주면 원하는 형태로 정렬된 숫자를
얻을 수 있다.
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 <iostream> | |
#include <vector> | |
#include <string> | |
#include <algorithm> | |
using namespace std; | |
int main() | |
{ | |
vector<int> v; | |
for (int i = 0; i < 3; ++i) { | |
int num; | |
cin >> num; | |
v.push_back(num); | |
} | |
sort(v.begin(), v.end()); | |
string s; | |
cin >> s; | |
for (int i = 0; i < 3; ++i) | |
cout << v[s[i] - 'A'] << " "; | |
return 0; | |
} |