using System;
using System.Text;
using System.Collections;

class SimpleVectorXComparer : IComparer
{
    public int Compare(Object a, Object b)
    {
        if (a is SimpleVector && b is SimpleVector)
        {
            SimpleVector p1 = (SimpleVector)a;
            SimpleVector p2 = (SimpleVector)b;

            return p1.X - p2.X;
        }

        throw new ArgumentException("Argument hat falschen TYp");
    }
}

class SimpleVectorYComparer : IComparer
{
    public int Compare(Object a, Object b)
    {
        if (a is SimpleVector && b is SimpleVector)
        {
            SimpleVector p1 = (SimpleVector)a;
            SimpleVector p2 = (SimpleVector)b;

            return p1.Y - p2.Y;
        }

        throw new ArgumentException("Argument hat falschen TYp");
    }
}


class SimpleVector : IComparable
{
    public int X;
    public int Y;

    public SimpleVector(int x, int y)
    {
        this.X = x;
        this.Y = y;
    }

    public override string ToString()
    {
        return String.Format("( " + X + " ; " + Y + " )");
    }

    public int CompareTo(object obj)
    {
        if (obj is SimpleVector)
        {
            SimpleVector p = (SimpleVector)obj;

            double diff = Math.Sqrt(X * X + Y * Y) - Math.Sqrt(p.X * p.X + p.Y * p.Y);

            if (diff > 0)
                return 1;
            else if (diff < 0)
                return -1;
            else
                return 0;
        }

        throw new ArgumentException("Argument hat falschen TYp");
    }
}


class Program
{
    static void Main(string[] args)
    {
        SimpleVector[] vectors = new SimpleVector[5];
        vectors[0] = new SimpleVector(10, 124);
        vectors[1] = new SimpleVector(-10, -124);
        vectors[2] = new SimpleVector(5, 56);
        vectors[3] = new SimpleVector(-1, 366);
        vectors[4] = new SimpleVector(8, 7);

        Console.WriteLine("\n Sortierung nach Länge \n");
        Array.Sort(vectors);

        foreach (SimpleVector v in vectors)
        {
            Console.WriteLine(v);
        }

        Console.WriteLine("\n Sortierung nach X \n");
        Array.Sort(vectors, new SimpleVectorXComparer());

        foreach (SimpleVector v in vectors)
        {
            Console.WriteLine(v);
        }

        Console.WriteLine("\n Sortierung nach Y \n");
        Array.Sort(vectors, new SimpleVectorYComparer());

        foreach (SimpleVector v in vectors)
        {
            Console.WriteLine(v);
        }
    }
}

