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

Wrong Answer
Posted by 1212346 27 Sep 2013 08:59
#include <stdio.h>
#include <iostream>
using namespace std;
#define MAX 15000

struct Team
{
    int ID;
    int M;
};

void Swap(Team &A, Team &B)
{
    Team temp = A;
    A = B;
    B = temp;
}

void QuickSort(Team A[], int left, int right)
{
    int    i, j;
    if (left >= right)
        return;
    int x = ((left + right)/2);
    i = left;
    j = right;
    while(i < j)
    {
        while (A[x].M < A[i].M)
            i++;
        while (A[j].M < A[x].M)
            j--;
        if(i <= j)
        {
            Swap(A[i], A[j]);
            i++;
            j--;
        }
    }
    QuickSort(A, left, j);
    QuickSort(A, i, right);
}

void main()
{
    int N;
    Team A[MAX];
    cin >> N;
    for (int i = 0; i < N; i++)
        cin >> A[i].ID >> A[i].M;
    QuickSort(A, 0, N - 1);
    for (int i = 0; i < N; i++)
        cout << A[i].ID << "  " << A[i].M << endl;
}