Click here to Skip to main content
15,885,896 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
example

input :

n=3

2  2  1 
3  53 4
32 5  3


output:

1  2  2
3  3 54
4 32 53


__________________
ok, here's ALL I CAN THINK OF! BUT IM PRETTY SURE ITS NOT WORKING!
WHY WOULD YOU GUYS REPORT MY QUESTION?!!!I DON UNDERSTAND!!

C#
static void Main()
{
   int n = int.parse(console.ReadLine());

   int [,] array1 = new int [n,n];

   for(int i=0;i<array1.getlength(0);++i)>
   for(int j=0;j<array1.getlength(1);++j)>
   array1[i,j]=int.parse(console.readline());

   for(int j=0;j<array1.getlength(1);++j)>
   for(int i=0;i<array1.getlength(0);++i)>
   Array.Sort<int>(array1)

   for(int i=0;i<array1.getlength(0);++j)>
   for(int j=0;j<array1.getlength(1);++i)>
   Array.Sort<int>(array1)
}
Posted
Updated 24-Apr-14 1:11am
v3

Check this: http://www.informit.com/guides/content.aspx?g=dotnet&seqNum=151[^]
PS: this is called sorting, not arranging.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 23-Apr-14 16:42pm    
5ed.
—SA
Zoltán Zörgő 23-Apr-14 16:43pm    
Thank you.
Sergey Alexandrovich Kryukov 23-Apr-14 16:51pm    
You are welcome. By the way, sorry about letting you know so late, but did you see my 1st of April article "Power Over IP: Testing of the First Experimental Facility"?
http://www.codeproject.com/Articles/752137/Power-Over-IP-Testing-of-the-First-Experimental-Fa

Hope it can add some good spring mood :-)
—SA
Emre Ataseven 23-Apr-14 17:23pm    
lol
Sergey Alexandrovich Kryukov 23-Apr-14 17:26pm    
Hope you like it... :-)
—SA
One thing you should be aware of: sorting a jagged array, an array of the form SomeArray[][] by columns is very easy to do with Linq; sorting a two-dimensional Array, an array of the form SomeArray[,] by columns requires nested iteration. See Marc Gravell's comments on this on StackOverFlow: [^], and, also, see: [^].

Technically, the problem with achieving column sort in a multi-dimensional array using Linq is related to the fact that it does not implement/support IEnumerable; a jagged array does.

I would approach this problem by making use of generic collections, and Linq. Here's a quick sketch:
C#
// required
using System.Collections.Generic;
using System.Linq;

private void TestSort()
{
    int[,] ints = new int[3,3]
    {
        {2, 2, 1}, {3, 53, 4}, {32, 5, 3}
    };

    List<List<int>> columns = new List<List<int>>();

    for (int i = 0; i < 3; i++)
    {
        List<int> column = new List<int>();

        for (int j = 0; j < 3; j++) column.Add(ints[j,i]);

        column.Sort();

        columns.Add(column);
    }

    List<List<int>> rows = new List<List<int>>();

    for (int i = 0; i < 3; i++)
    {
        List<int> row = new List<int>();

        for (int j = 0; j < 3; j++) row.Add(columns[j][i]);

        row.Sort();

        rows.Add(row);
    }

    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < 3; j++) ints[i, j] = rows[i][j];
    }            
}
I suggest you set break-points, and execute this code and examine the contents of the different Lists as they are defined, and sorted.

Yes, this is a "brute force" solution, and, with effort, I am sure one could make it "leaner and meaner."
 
Share this answer
 
v2
Comments
Alexis i 25-Apr-14 6:03am    
thank you thank you thank you thank you * 1000000000

i wanna kiss you!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900