Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.46 KB | None | 0 0
  1. static void sprawdzenie(int[]ciagwyjsciowy)
  2.         {
  3.             int[] ciagwejsciowy = new int[ciagwyjsciowy.Length];
  4.             for (int i = 0; i < ciagwejsciowy.Length; i++)
  5.             {
  6.                 ciagwejsciowy[i] = i;
  7.             }
  8.             Stack<int> s1 = new Stack<int>();
  9.             Queue<int> q1 = new Queue<int>();
  10.             int[] wyjscie = new int[ciagwejsciowy.Length];
  11.             int tmp = 0;
  12.             int j = 0;
  13.             for (int i = 0; i < ciagwejsciowy.Length; i++)
  14.             {
  15.                  tmp = ciagwejsciowy[i];
  16.                 s1.Push(tmp);
  17.  
  18.                 while (s1.Count > 0 && tmp >= ciagwyjsciowy[j])
  19.                 {
  20.                     q1.Enqueue(s1.Pop());
  21.                     j++;
  22.                 }
  23.  
  24.  
  25.             }
  26.             foreach (var item in q1)
  27.             {
  28.                 Console.Write(item + " ");
  29.             }
  30.             for (int i = 0; i < wyjscie.Length; i++)
  31.             {
  32.                 wyjscie[i] = q1.Dequeue();
  33.             }
  34.             bool mozliwe = true;
  35.             for (int i = 0; i < ciagwejsciowy.Length; i++)
  36.             {
  37.                 if (ciagwyjsciowy[i]!=wyjscie[i])
  38.                 {
  39.                     mozliwe = false;
  40.                     Console.WriteLine($"czy jest mozliwe?  {mozliwe}");
  41.                     return;
  42.                 }
  43.             }
  44.             //mozliwe = true;
  45.             Console.WriteLine($"czy jest mozliwe?  {mozliwe}");
  46.  
  47.  
  48.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement