Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.88 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace TestConsole {
  8.     class Program {
  9.         static void Main(string[] args) {
  10.             int[] data = { 6, 9, 12, 3, 6, 9, 12, 3, 6, 9, 12, 3, 6, 9, 12, 3, 6, 9, 12, 3, 6, 9, 12, 3, 6, 9, 12, 3, 6, 9, 12, 3, 6, 9, 12, 3, 6, 9, 12, 3, 6, 9, 12, 3, 6, 9, 12, 3, 6, 9, 12, 3, 6, 9, 12, 3, 6, 9, 12, 3, 6, 9, 12, 3, 6, 9, 12, 3, 6, 9, 12, 3, 6, 9, 12, 3, 6, 9, 12, 3, 6, 9, 12, 3, 6, 9, 12, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4 };
  11.             var rez = SplitArray(data);
  12.             foreach (int[] intarr in rez) {
  13.                 Console.Write("[");
  14.                 foreach (int item in intarr) {
  15.                     Console.Write(item+", ");
  16.                 }
  17.                 Console.Write("]" + Environment.NewLine);
  18.             }
  19.             Console.ReadLine();
  20.         }
  21.  
  22.         static List<int[]> SplitArray (int[] arr) {
  23.             var rez = new List<int[]>();
  24.             if (arr.Length==1) {
  25.                 rez.Add(arr);
  26.                 return rez;
  27.             }
  28.             int size = 0;
  29.             for (int i = 1; i < arr.Length; i++) {
  30.                 size++;
  31.                 if (arr[i] < arr[i - 1]) {
  32.                     rez.Add(arr.Skip(i - size).Take(size).ToArray());
  33.                     size = 0;
  34.                 }
  35.             }
  36.             return rez;
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement