Notice
Recent Posts
Recent Comments
Link
Little Jay
[C++] 백준 2822번 점수계산 본문
vector 기능 중 pair을 처음 써본 문제
pair만 제대로 이해했다면 조금은 쉬운 예제
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstdlib>
using namespace std;
int main() {
vector<pair<int, int>> inputList;
const int INPUT_NUM = 8;
int inputNumber;
for (int i = 0; i < INPUT_NUM; i++) {
cin >> inputNumber;
inputList.push_back(make_pair(inputNumber, i + 1));
}
sort(inputList.begin(), inputList.end(), greater<pair<int, int>>());
int sum = 0;
vector<int> index;
for (int i = 0; i < 5; i++) {
sum += inputList[i].first;
index.push_back(inputList[i].second);
}
cout << sum << "\n";
sort(index.begin(), index.end());
for (int k = 0; k < index.size(); k++) {
cout << index[k] << " ";
}
cout << "\n";
inputList.clear();
index.clear();
return 0;
}'알고리즘 > BOJ' 카테고리의 다른 글
| [C++] 백준 2747번 피보나치 수 (0) | 2021.02.28 |
|---|---|
| [C++] 백준 2693번 N번째 큰 수 (0) | 2021.02.28 |
| [C++] 백준 3507번 Automated Telephone Exchange (0) | 2021.02.27 |
| [C++] 백준 18108번 1998년생인 내가 태국에서는 2541년생?! (0) | 2021.02.27 |
| [C++] 백준 2743번 단어 길이 재기 (0) | 2021.02.27 |
Comments