Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
Tags
- 컴공과
- 문제풀이
- 컴퓨터공학과
- 자료구조
- cs
- 오퍼레이팅시스템
- vector
- 코딩
- Stack
- 너비우선탐색
- 코테
- 북리뷰
- 스택
- Computer science
- coding
- 정석학술정보관
- bfs
- 컴공
- 브루트포스
- DP
- Operating System
- c++
- 백준
- 오에스
- 개발
- 정석
- 알고리즘
- 구현
- OS
- 그래프
Archives
- Today
- Total
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