입출력
풀이
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int cnt;
cin >> cnt;
int x, y;
vector<pair<int, int>> xys;
for (int i = 0; i < cnt; i++)
{
cin >> x >> y;
xys.push_back(make_pair(y, x));
}
sort(xys.begin(), xys.end());
for (int i = 0; i < cnt; i++)
{
cout << xys[i].second << " " << xys[i].first << "\n";
}
}
#백준11650 전 문제와 풀이는 동일하다
vector.first에 y값을, vector.second에 값을 넣어주면 sort함수가 알아서 정렬해준다
https://yeonjingameprogramming.tistory.com/4
백준 11650 좌표 정렬하기 (C++)
입출력 풀이 #include #include #include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int cnt; int x, y; vector xys; cin >> cnt; for (int i = 0; i < cnt; i++) { cin >> x >> y; xys.push_back({ x, y });//xy
yeonjingameprogramming.tistory.com
'> 코딩테스트' 카테고리의 다른 글
[백준] 10815 숫자 카드 (C++) (1) | 2023.06.11 |
---|---|
[백준] 10814 나이순 정렬 (C++) (0) | 2023.06.07 |
[백준] 1181 단어 정렬 (C++) (0) | 2023.06.06 |
[백준] 11650 좌표 정렬하기 (C++) (0) | 2023.06.04 |
[백준] 10989 수 정렬하기 (C++) (0) | 2023.06.04 |