#include <bits/stdc++.h>
using namespace std;
bool cmp(int *a, int *b){
if(a[0] == b[0]) return a[1] < b[1];
else return a[0] < b[0];
}
int main(){
int arr[10][2];
int n=10;
for(int i=0;i<n;i++) scanf(" %d %d",&arr[i][0], &arr[i][1]);
sort(arr, arr+n,cmp);
}
this code is just simple thing. your input is just like
3 2
3 1
1 1
2 2
6 6
4 4
5 5
7 7
8 8
9 9
and output should be like
1 1
2 2
3 1
3 2
4 4
5 5
6 6
7 7
8 8
9 9
simply you can think pair<int,int>.
let's say pair<int,int> to pair<a,b>.
i want to sort 'a' firstly. and if 'a' is same, then you should sort it by 'b'. (it's ascending sort)
so I have been trying to sort the array like this. but it doesn't work.
yea I know it's pretty easy if you use 'vector', but I don't want to use it. and I'm gonna use std::sort only.
of course you can't compile this because it's wrong.
I googled this problem but couldn't find anything. is there any way to solve this?
there is so many error code if you run this, so here's the error code that compiler brought directly to me.
1849 11 C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\bits\stl_algo.h [Error] array must be initialized with a brace-enclosed initializer