Advertisement
Egonau

Untitled

Nov 20th, 2020
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.75 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApp2
  4. {
  5.  
  6.  
  7.  
  8.     class Program
  9.     {
  10.         public static void deque(int[] stack1, int i, int num, ref int nach2, ref int kon2)
  11.         {
  12.  
  13.             if (i == 1)//push_back
  14.             {
  15.                 stack1[kon2] = num;
  16.                 kon2++;
  17.             }
  18.             if (i == 2)//push_front
  19.             {
  20.                 stack1[nach2] = num;
  21.                 nach2--;
  22.             }
  23.         }
  24.  
  25.         static void Main(string[] args)
  26.         {
  27.  
  28.             int n;
  29.             n = int.Parse(Console.ReadLine());
  30.             int[] firsthalf = new int[1000000];
  31.             int[] secondhalf = new int[1000000];
  32.             string[] a;
  33.             int nach1 = 0;
  34.             int kon1 = 0;
  35.             int nach2 = 499999;
  36.             int kon2 = 500000;
  37.  
  38.             for (int i = 0; i < n; ++i)
  39.             {
  40.                 while (kon1 - nach1 < kon2 - nach2 - 1)
  41.                 {
  42.                     firsthalf[kon1] = secondhalf[nach2 + 1];
  43.                     secondhalf[nach2 + 1] = 0;
  44.                     kon1++;
  45.                     nach2++;
  46.                 }
  47.                 a = Console.ReadLine().Split();
  48.                 if (a[0] == "+")
  49.                 {
  50.                     Program.deque(secondhalf, 1, int.Parse(a[1]), ref nach2, ref kon2);
  51.                    
  52.                 }
  53.                
  54.                 if (a[0] == "*")
  55.                 {
  56.                    
  57.                     Program.deque(secondhalf, 2, int.Parse(a[1]), ref nach2, ref kon2);
  58.                    
  59.                 }
  60.                 if (a[0] == "-")
  61.                 {
  62.                     Console.WriteLine(firsthalf[nach1]);
  63.                     nach1++;
  64.                 }
  65.             }
  66.         }
  67.     }
  68. }
  69.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement