ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1100. Final Standings

WA... I may be wrong to pass parameters to the function qsort?
Posted by viktorius 15 Jul 2013 10:05
#include<stdio.h>
#include<stdlib.h>
int compare(const void *a, const void *b)
{
    if(*(*(int**)a+1)<*(*(int**)b+1))
        return 1;
    else
        return -1;
}
int main()
{
    int n,i,**arr;
    scanf("%d",&n);
    arr=(int**)calloc(n,sizeof(int*));
    for(i=0;i<n;i++)
    {
        arr[i]=(int*)calloc(2,sizeof(int));
        scanf("%d %d",&arr[i][0],&arr[i][1]);
    }
    qsort(arr,n,4,compare);
    for(i=0;i<n;i++)
    {
        printf("%d %d\n",arr[i][0],arr[i][1]);
        free(arr[i]);
    }
    free(arr);
    return 0;
}
Re: WA... I may be wrong to pass parameters to the function qsort?
Posted by SazanovSasha 23 Jul 2013 14:47
Reread the condition.
You must output the same results table as bubble sort, but faster.
Qsort gives other result.
Test output:    Yuor output:
3 5         3 5
26 4        26 4
22 4        22 4
16 3        20 3
20 3        16 3
1 2        11 2
11 2        1 2
7 1        7 1

WA


Edited by author 23.07.2013 14:47