1. What I learned
a. Vector<>
Vector is simply an array of dynamically changing lengths.
b. sort(Vector<>)
To sort the internal values of vectors in ascending order, sort() in the ‘algorithm’ header file can be used.
2. Code
#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;
int main(void) {
int num_of_points, x, y;
vector<pair<int,int> > points;
scanf("%d", &num_of_points);
for (int i=0 ; i<num_of_points ; i++) {
scanf("%d %d", &x, &y);
points.push_back(pair<int,int>(y,x));
}
sort(points.begin(), points.end());
for (int i=0 ; i<num_of_points ; i++) {
printf("%d %d\n", points[i].second, points[i].first);
}
return 0;
}
3. Result
Runtime : 64 ms, Memory usage : 2776 KB
(Runtime can be different by a system even if it is a same code.)