goorm
(구름 먼데이챌린지 c++ 2주차)3. 출석부
naeunchan
2022. 10. 31. 18:56
728x90
반응형
goorm
구름은 클라우드 기술을 이용하여 누구나 코딩을 배우고, 실력을 평가하고, 소프트웨어를 개발할 수 있는 클라우드 소프트웨어 생태계입니다.
goorm.co
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
bool asc(pair<string, double> a, pair<string, double> b){
if(a.first == b.first){
return a.second < b.second;
}
return a.first < b.first;
}
int main() {
int N, target;
vector<pair<string, double>> v;
cin >> N >> target;
for(int i = 0; i < N; i++){
string s;
double h;
cin >> s >> h;
v.push_back({s, h});
}
sort(v.begin(), v.end(), asc);
cout << fixed;
cout.precision(2);
cout << v[target - 1].first << " " << v[target - 1].second;
return 0;
}
vector로 이름과 키를 pair 형으로 받아 이를 주어진 조건대로 정렬하면 된다.
만약 이름순으로 하되 이름이 같다면 키가 작은 순으로 하면 된다.
cout << fixed와 cout.precision(2)는 소수점 2자리까지 출력하기 위함이다.
728x90
반응형