Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Collections.Generic;
- using System.Linq;
- using System.Runtime.Serialization.Formatters.Binary;
- namespace lab4
- {
- class Program
- {
- static int n = 0;
- static private Random rnd = new Random();
- static List <int> list = new List<int>();
- static List<int> list_f = new List<int>();
- static int[,] arr = new int[40, 40];
- static void Write_(FileStream f)
- {
- try
- {
- using (f)
- {
- using (BinaryWriter fout = new BinaryWriter(f))
- {
- Console.WriteLine("Исходный файл:");
- int a;
- int n = rnd.Next(5, 20);
- for (int i = 1; i <= n; i++)
- {
- a = rnd.Next(-10, 10);
- Console.Write(a + " ");
- fout.Write(a);
- }
- }
- }
- }
- catch(IOException e)
- {
- Console.WriteLine("Error:" + e.Message);
- return;
- }
- }
- static void Read_(FileStream f)
- {
- int a;
- try
- {
- using (f)
- {
- using (BinaryReader F = new BinaryReader(f))
- {
- for (; F.BaseStream.Position < F.BaseStream.Length;)
- {
- a = F.ReadInt32();
- list.Add(a);
- }
- }
- }
- }
- catch (FileNotFoundException e)
- {
- Console.WriteLine("Проверьте правильность имени файла" + e.Message);
- return;
- }
- catch (Exception e)
- {
- Console.WriteLine("Error:" + e.Message);
- return;
- }
- }
- static void Save(string fileName)
- {
- BinaryFormatter bf = new BinaryFormatter();
- using (Stream writer = new FileStream(fileName, FileMode.Create))
- {
- bf.Serialize(writer, list);
- }
- }
- static void Load(string fileName)
- {
- BinaryFormatter bf = new BinaryFormatter();
- using (Stream reader = new FileStream(fileName, FileMode.Open))
- {
- list_f = (List<int>)bf.Deserialize(reader);
- }
- }
- static void inp()
- {
- string buf;
- Console.WriteLine();
- Console.WriteLine("Введите n");
- buf = Console.ReadLine();
- n = int.Parse(buf);
- int k = 0;
- for (int i=0; i< n; i++)
- {
- for (int j=0; j<n; j++)
- {
- if (k <= list_f.Count - 1)
- arr[i, j] = list[k];
- else break;
- k++;
- }
- }
- }
- static void out1(int[,] arr) //вывод массива
- {
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < n; j++)
- {
- Console.Write("{0}\t", arr[i, j]);
- }
- Console.WriteLine();
- }
- }
- static int find(int [] max_, int str)
- {
- for (int i = 0; i < str; i++)
- {
- for (int j = 0; j < n; j++)
- {
- max_[i] *= arr[i,j];
- }
- }
- Console.WriteLine();
- for (int i = 0; i < str; i++)
- Console.WriteLine(max_[i]);
- int max = Array.IndexOf(max_, max_.Max());
- return max;
- }
- static void reverse(int rez)
- {
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < n; j++)
- {
- arr[i,j] = arr[rez, j];
- }
- }
- }
- static void Main(string[] args)
- {
- FileStream f = new FileStream("test.dat", FileMode.Create);
- Write_(f);
- FileStream f1 = new FileStream("test.dat", FileMode.Open);
- Read_(f1);
- var uniq = list.Distinct();
- list = uniq.ToList();
- Save("finish.dat");
- Load("finish.dat");
- Console.WriteLine();
- foreach (var item in list_f)
- {
- Console.Write(item + " ");
- }
- inp();
- out1(arr);
- int str;
- str = list_f.Count / n;
- Console.WriteLine();
- Console.WriteLine("Количество заполненных строк " + str);
- int[] max_ = new int[str];
- for (int i = 0; i < str; i++)
- {
- max_[i] = 1;
- }
- int rez =find(max_, str);
- reverse(rez);
- Console.WriteLine();
- out1(arr);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement