Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.IO;
- using System.Xml.Serialization;
- namespace ConsoleApp6
- {
- class Program
- {
- static void Main(string[] args)
- {
- FileStream fS = new FileStream("input.csv", FileMode.Open);
- StreamReader sR = new StreamReader(fS);
- List<int[,]> Matr = new List<int[,]>();
- string cur = "";
- int ind = 0;
- int indstr = 0;
- while ((cur = sR.ReadLine()) != null)
- {
- string[] str = cur.Split(',');
- int[] num = new int[str.Length];
- for (int i = 0; i < str.Length; i++)
- if (!int.TryParse(str[i], out num[i]))
- {
- string cur1 = "";
- for (int j = 0; j < str[i].Length; j++)
- if (str[i][j] >= '0' & str[i][j] <= '9')
- cur1 += str[i][j];
- int.TryParse(cur1, out num[i]);
- }
- if (Matr.Count == 0)
- {
- Matr.Add(new int[num.Length, num.Length]);
- indstr = num.Length;
- for (int i = 0; i < Matr[ind].GetLength(1); i++)
- Matr[ind][num.Length - indstr, i] = num[i];
- indstr = num.Length - 1;
- continue;
- }
- if (indstr > 0 & Matr[ind].GetLength(0) != num.Length)
- {
- for (int i = Matr[ind].GetLength(0) - indstr; i < Matr[ind].GetLength(1); i++)
- for (int j = 0; j < Matr[ind].GetLength(1); j++)
- Matr[ind][i, j] = 0;
- indstr = 0;
- }
- if (indstr == 0)
- {
- ind++;
- Matr.Add(new int[num.Length, num.Length]);
- indstr = num.Length;
- for (int i = 0; i < Matr[ind].GetLength(1); i++)
- Matr[ind][num.Length - indstr, i] = num[i];
- indstr = num.Length - 1;
- }
- else
- {
- for (int i = 0; i < Matr[ind].GetLength(1); i++)
- Matr[ind][num.Length - indstr, i] = num[i];
- indstr--;
- }
- }
- foreach (var a in Matr)
- {
- for (int i = 0; i < a.GetLength(1); i++)
- for (int j = 0; j < a.GetLength(1); j++)
- {
- Console.Write(a[i, j]);
- if (j + 1 == a.GetLength(1))
- Console.WriteLine();
- else
- {
- Console.Write(" ");
- }
- }
- Console.WriteLine("-------------------------");
- }
- Console.WriteLine();
- IEnumerable<int[,]> mat = from a in Matr
- where MainDiag(a)
- select a;
- foreach (var a in mat)
- {
- for (int i = 0; i < a.GetLength(1); i++)
- for (int j = 0; j < a.GetLength(1); j++)
- {
- Console.Write(a[i, j]);
- if (j + 1 == a.GetLength(1))
- Console.WriteLine();
- else
- {
- Console.Write(" ");
- }
- }
- Console.WriteLine("-------------------------");
- }
- IEnumerable<int[,]> mat2 = from a in Matr
- where MainElement(a)
- select a;
- Console.WriteLine();
- foreach (var a in mat2)
- {
- for (int i = 0; i < a.GetLength(1); i++)
- for (int j = 0; j < a.GetLength(1); j++)
- {
- Console.Write(a[i, j]);
- if (j + 1 == a.GetLength(1))
- Console.WriteLine();
- else
- {
- Console.Write(" ");
- }
- }
- Console.WriteLine("-------------------------");
- }
- XmlSerializer xml = new XmlSerializer(typeof(int[,]));
- FileStream newfS = new FileStream("text.xml",FileMode.Create);
- foreach (var a in mat2)
- xml.Serialize(newfS,a);
- }
- static public bool MainDiag(int[,] a)
- {
- int z = 0;
- for(int i=0;i<a.GetLength(1);i++)
- {
- if (a[i, i] == 0)
- z++;
- }
- return z >= 3;
- }
- static public bool MainElement(int[,] a)
- {
- int z = -100;
- int ind1 = -1;
- int ind2 = 0;
- for (int i = 0; i < a.GetLength(1); i++)
- for (int j = 0; j < a.GetLength(1); j++)
- if (a[i, j] > z)
- {
- z = a[i, j];
- ind1 = i;
- ind2 = j;
- }
- else if(a[i, j] == z)
- {
- if(j>i)
- {
- ind1 = i;
- ind2 = j;
- }
- }
- return ind2 > ind1;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement