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

Show all messages Hide all messages

Такой вывод для первого теста подходит, т.к. "говорит" WA2
Console.Write("3 5\n26 4\n22 4\n16 3\n20 3\n1 2\n11 2\n7 1\n");

А этот WA1. В упор... =( .
--------------------------------
using System;
using System.Collections.Generic;

class Program
{
    struct TRec { public int ID, M; }
    static int Comp(TRec x, TRec y)
    {
        if (y.M < x.M) return -1;
        else if (y.M > x.M) return 1;
        else return 0;
    }

    static void Main()
    {
        int N = int.Parse(Console.ReadLine());
        List<TRec> D = new List<TRec>();

        string[] RecStr;
        for (int i = 0; i < N; i++)
        {
            RecStr = Console.ReadLine().Split(' ');

            TRec R = new TRec();
            R.ID = int.Parse(RecStr[0]);
            R.M = int.Parse(RecStr[1]);
            D.Add( R );
        }

        D.Sort(Comp);

        foreach (TRec X in D)
            Console.Write("{0} {1}\n", X.ID, X.M);
        Console.ReadLine();
    }
}
Делаю в C#2012. Неужто в 2010 quick_sort работает по другому?
hi!
Need to use stable sort. I add extra field - ind, to compare 2 entry.
using System;
using System.Collections.Generic;

class Program
{
    struct TRec { public int ID, M, ind;}
    static int Comp(TRec x, TRec y)
    {
        if (y.M < x.M || (y.M == x.M && y.ind > x.ind))
            return -1;
        if (y.M > x.M || (y.M == x.M && y.ind < x.ind))
            return 1;
        return 0;
    }

    static void Main()
    {
        int N = int.Parse(Console.ReadLine());
        List<TRec> D = new List<TRec>();

        string[] RecStr;
        for (int i = 0; i < N; i++)
        {
            RecStr = Console.ReadLine().Split(' ');

            TRec R = new TRec();
            R.ID = int.Parse(RecStr[0]);
            R.M = int.Parse(RecStr[1]);
            R.ind = i;
            D.Add(R);
        }

        D.Sort(Comp);

        foreach (TRec X in D)
            Console.Write("{0} {1}\n", X.ID, X.M);
        Console.ReadLine();
    }
}