피너클의 it공부방
백준 2535 아시아 정보올림피아드 (c++) : 피너클 본문
728x90
반응형
https://www.acmicpc.net/problem/2535
2535번: 아시아 정보올림피아드
첫 번째 줄에는 대회참가 학생 수를 나타내는 N이 주어진다. 단, 3 ≤ N ≤ 100이다. 두 번째 줄부터 N개의 줄에는 각 줄마다 한 학생의 소속 국가 번호, 학생 번호, 그리고 성적이 하나의 빈칸을 사
www.acmicpc.net
간단한 구현문제다.
cin >> n;
for (int i = 0; i < n; i++) {
num[i + 1] = 0;
int a, b, c;
cin >> a >> b >> c;
v.push_back({ c, {a, b} });
}
sort(v.begin(), v.end(), greater<pair<int, pair<int, int>>>());
벡터에 입력받는다. 받을때 {점수, {참가국, 학생번호}} 순으로 받는다. 그후 크기순으로 정렬한다.
int a = 0;
for (int i = 0; i < n; i++) {
if (num[v[i].second.first] >= 2) continue;
a++;
num[v[i].second.first]++;
cout << v[i].second.first << ' ' << v[i].second.second << endl;
if (a == 3) break;
}
a는 현재까지 출력한 횟수를 나타낸다.
반복문을 돌리며 만약 현재 국가가 2번이상 나타난 국가라면 뒤의 문장들을 무시한다.
아니라면 a++해주고 num[현재국가]++해준다.
그후 참가국과 학생 번호를 출력하고 만약 a가 3이라면 3번 출력한것이니 break한다.
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int n;
vector<pair<int, pair<int, int>>> v;
int num[101];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 0; i < n; i++) {
num[i + 1] = 0;
int a, b, c;
cin >> a >> b >> c;
v.push_back({ c, {a, b} });
}
sort(v.begin(), v.end(), greater<pair<int, pair<int, int>>>());
int a = 0;
for (int i = 0; i < n; i++) {
if (num[v[i].second.first] >= 2) continue;
a++;
num[v[i].second.first]++;
cout << v[i].second.first << ' ' << v[i].second.second << endl;
if (a == 3) break;
}
}
전체코드다.
728x90
반응형
'백준' 카테고리의 다른 글
백준 4101 크냐? (c++) : 피너클 (0) | 2022.07.20 |
---|---|
백준 14440 정수 수열 (c++) : 피너클 (0) | 2022.07.19 |
백준 2034 반음 (c++) : 피너클 (0) | 2022.07.18 |
백준 1417 국회의원 선거 (c++) : 피너클 (0) | 2022.07.17 |
백준 1817 짐 챙기는 숌 (c++) : 피너클 (0) | 2022.07.16 |
Comments