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.Collections;
- namespace rep_c_sharp
- {
- class Program
- {
- static List<int[]> InsertR()
- {
- int countPairs = 0;
- List<int[]> R = new List<int[]>();
- Console.Write("Введите количесвто пар: ");
- countPairs = int.Parse(Console.ReadLine());
- for (int i = 0; i < countPairs; i++)
- {
- int[] pair = new int[2];
- Console.WriteLine("---------------------------\nВведите " + i + " пару\n---------------------------");
- for (int j = 0; j < pair.Length; j++)
- {
- Console.WriteLine("Введите " + j + " значение");
- pair[j] = int.Parse(Console.ReadLine());
- }
- R.Add(pair);
- }
- return R;
- }
- static void ShowPairs(List<int[]> R)
- {
- Console.WriteLine("\nВывод R");
- foreach (int[] pair in R)
- {
- for (int i = 0; i < pair.Length; i++)
- {
- if (i == 0)
- Console.Write("{" + pair[i] + ", ");
- else
- Console.Write(pair[i] + "}");
- }
- Console.WriteLine();
- }
- }
- static int[,] ConvertToMatrix(List<int[]> R, List<int> X)
- {
- int len = 0;
- len = X.Count();
- int[,] matrix = new int[len, len];
- for (int i = 0; i < len; i++)
- {
- for (int j = 0; j < len; j++)
- {
- matrix[i, j] = 0;
- }
- }
- foreach (int[] pair in R)
- {
- matrix[X.IndexOf(pair[0]), X.IndexOf(pair[1])] = 1;
- }
- return matrix;
- }
- static void ShowMatrix(int[,] matrix, List<int> X)
- {
- for (int i = 0; i < matrix.GetLength(0); i++)
- {
- for (int j = 0; j < matrix.GetLength(1); j++)
- {
- Console.Write(matrix[i, j] + "\t");
- }
- Console.WriteLine();
- }
- }
- static void Main(string[] args)
- {
- List<int> X = new List<int>();
- Console.Write("Введите размер 'X': ");
- int lenX = int.Parse(Console.ReadLine());
- for(int i = 0; i < lenX; i++)
- {
- Console.Write("Введите X[" + i + "]: ");
- X.Add(int.Parse(Console.ReadLine()));
- }
- Console.Write("X: ");
- Console.WriteLine(String.Join(", ", X));
- List<int[]> R = InsertR();
- ShowPairs(R);
- int[,] matrixR = ConvertToMatrix(R, X);
- ShowMatrix(matrixR, X);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement