using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace p19
{
class Program
{
static void citire(out int n, out int[,] A, string fis)
{//citire matrice patratica din fisier precizat prim param
StreamReader fin = new StreamReader(fis);
n = int.Parse(fin.ReadLine());
A = new int[n, n];
for (int i = 0; i < n; i++)
{
string linie = fin.ReadLine();
string[] s = linie.Split();
for (int j = 0; j < n; j++)
A[i, j] = int.Parse(s[j]);
}
fin.Close();
}
static void afisare(int n, int[,] A, string fis)
{//afisare matrice patratica in fisier precizat prin param
StreamWriter fout = new StreamWriter(fis);
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
fout.Write(A[i, j] + " ");
fout.WriteLine();
}
fout.Close();
}
static void inter(ref int a, ref int b)
{//interchimba doua valori
int aux = a; a = b; b = aux;
}
static void intercol(int n, int[,] A, int i, int j)
{//interschimba coloana i cu coloana j in matricea A
for (int k = 0; k < n; k++)
inter(ref A[k, i], ref A[k, j]);
}
static void ordonare(int n, int[,] A)
{//ordoneaza crescator prima linie prin interschimbari de coloane
for (int i = 0; i < n; i++)
for (int j = i + 1; j < n; j++)
if (A[0, i] > A[0, j])
intercol(n, A, i, j);
}
static void Main(string[] args)
{
int n;
int[,] A;
citire(out n, out A, "date.in");
ordonare(n, A);
afisare(n, A, "date.out");
}
}
}
|