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;
- namespace StalinArray
- {
- class Program
- {
- static void Main(string[] args)
- {
- Random r = new Random();
- int min_count = 10;
- int max_count = 21;
- int l = r.Next(min_count, max_count);
- int[] a = new int[l];
- for (int i = 0; i < l; i++) a[i] = i + 1;
- foreach (int i in a) Console.Write("{0} ", i);
- Console.WriteLine();
- Console.ForegroundColor = ConsoleColor.Green;
- Console.WriteLine("Перемешивание...");
- int magic_count = r.Next(min_count, max_count);
- Console.WriteLine("{0} замен...", magic_count);
- Console.ForegroundColor = ConsoleColor.Gray;
- int t, i1, i2;
- for (int i = 0; i < magic_count; i++)
- {
- i1 = r.Next(0, l);
- i2 = r.Next(0, l);
- t = a[i1];
- a[i1] = a[i2];
- a[i2] = t;
- }
- foreach (int i in a) Console.Write("{0} ", i);
- Console.WriteLine();
- Console.ForegroundColor = ConsoleColor.Green;
- Console.WriteLine("Сдвиги...");
- Console.ForegroundColor = ConsoleColor.Gray;
- List<List<int>> tarr = new List<List<int>>();
- tarr.Add(new List<int>(a));
- for (int i = 0; i < tarr.Count; i++)
- {
- for (int q = 1; q < tarr[i].Count; q++)
- {
- if (tarr[i][q] < tarr[i][q - 1])
- {
- if (i + 1 >= tarr.Count) tarr.Add(new List<int>());
- tarr[i + 1].Add(tarr[i][q]);
- tarr[i].RemoveAt(q);
- q--;
- }
- }
- }
- for (int i = 0; i < tarr.Count; i++)
- {
- for (int q = 0; q < tarr[i].Count; q++)
- {
- Console.Write("{0} ", tarr[i][q]);
- }
- Console.WriteLine();
- }
- Console.ForegroundColor = ConsoleColor.Green;
- Console.WriteLine("Волшебная магия...");
- Console.ForegroundColor = ConsoleColor.Gray;
- List<int> res = new List<int>();
- int ti;
- while (tarr.Count > 0)
- {
- if (tarr[0].Count < 1)
- {
- tarr.RemoveAt(0);
- continue;
- }
- ti = 0;
- for (int i = 1; i < tarr.Count; i++)
- {
- if(tarr[i].Count < 1)
- {
- tarr.RemoveAt(i);
- i--;
- continue;
- }
- if (tarr[ti][0] > tarr[i][0]) ti = i;
- }
- res.Add(tarr[ti][0]);
- tarr[ti].RemoveAt(0);
- }
- foreach (int i in res) Console.Write("{0} ", i);
- Console.WriteLine();
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement