Bob103

C#_5_(VI-10)

Oct 14th, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.14 KB | None | 0 0
  1. class Program
  2.     {
  3.         static void setarray(out int[][] arr)
  4.         {
  5.             Console.Write("Введите кол-во строк n=");
  6.             int n = Convert.ToInt32(Console.ReadLine());
  7.             arr = new int[n][];
  8.             for (int i = 0; i < arr.Length; i++)
  9.             {
  10.                 Console.Write("Введите количество элементов в {0} строке: ", i);
  11.                 int j = int.Parse(Console.ReadLine());
  12.                 arr[i] = new int[j];
  13.                 for (j = 0; j < arr[i].Length; j++)
  14.                 {
  15.                     Console.Write("arr[{0}][{1}]= ", i, j);
  16.                     arr[i][j] = int.Parse(Console.ReadLine());
  17.                 }
  18.             }
  19.         }
  20.  
  21.         static void Print(int[][] a)
  22.         {
  23.             foreach (int[] t in a)
  24.                 Console.WriteLine(String.Join(" ", t));
  25.         }
  26.  
  27.         static bool CheckInterval(int[][] a, int row, int inf, int sup)
  28.         {
  29.             for (int i = 0; i < a[row].Length; ++i)
  30.                 if (a[row][i] < inf || a[row][i] > sup)
  31.                     return false;
  32.  
  33.             return true;
  34.         }
  35.  
  36.         static void Delete(ref int[][] a, int inf, int sup)
  37.         {
  38.             int i = 0;
  39.             int len = a.Length;
  40.  
  41.             while (i < len)
  42.             {
  43.                 if (CheckInterval(a, i, inf, sup))
  44.                 {
  45.                     int j = i;
  46.  
  47.                     while (j < len - 1)
  48.                         a[j] = a[++j];
  49.  
  50.                     --len;
  51.                 }
  52.                 else
  53.                     ++i;
  54.             }
  55.  
  56.             Array.Resize(ref a, len);
  57.         }
  58.  
  59.         static void Main()
  60.         {
  61.             int[][] arr;
  62.             setarray(out arr);
  63.             Print(arr);
  64.             Console.Write("Введите a=");
  65.             int a = Convert.ToInt32(Console.ReadLine());
  66.             Console.Write("Введите a=");
  67.             int b = Convert.ToInt32(Console.ReadLine());
  68.             Console.WriteLine("После удаления:");
  69.             Delete(ref arr, a, b);
  70.             Print(arr);
  71.         }
  72.     }
Advertisement
Add Comment
Please, Sign In to add comment