thanks for your answer. 
Just now, I asked my Friend about this problem and he told me that he used the qsort and two dimension array, not a struct.
I tried to write a code once more.
#include <iostream>
#include <algorithm>
using namespace std;
int compare (const void * a, const void * b)
{
return ( *(int*)a - *(int*)b );
}
int main()
{
int t;
scanf("%d", &t);
while (t--)
{ int n;
scanf("%d", &n);
int nail, pos_nail, a[2][n];
for (int i=0; i<n; i++)
scanf("%d %d", &a[0][i], &a[1][i]);
qsort(a, n, 2*sizeof(int), compare);
pos_nail=a[1][0];
nail=0;
for(int j=0; j<n; j++)
printf("a[%d]= %d b =%d\n", j, a[0][j], a[1][j]);
for(int i=1; i<n; i++)
{
if(a[0][i]>=pos_nail)
{
nail++;
pos_nail=a[1][i];
}
}
printf("%d\n", nail);
}
return 0;
}
but it does not work yet.
actually, I want to sort the a[0][i], and the a[1][i] will follow the a[0][i] besause both of them are correspondence to one another.
can you help me how to sort this?
Thanks 