Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace ConsoleApp2
- {
- class Program
- {
- public static void deque(int[] stack1, int i, int num, ref int nach2, ref int kon2)
- {
- if (i == 1)//push_back
- {
- stack1[kon2] = num;
- kon2++;
- }
- if (i == 2)//push_front
- {
- stack1[nach2] = num;
- nach2--;
- }
- }
- static void Main(string[] args)
- {
- int n;
- n = int.Parse(Console.ReadLine());
- int[] firsthalf = new int[1000000];
- int[] secondhalf = new int[1000000];
- string[] a;
- int nach1 = 0;
- int kon1 = 0;
- int nach2 = 499999;
- int kon2 = 500000;
- for (int i = 0; i < n; ++i)
- {
- while (kon1 - nach1 < kon2 - nach2 - 1)
- {
- firsthalf[kon1] = secondhalf[nach2 + 1];
- secondhalf[nach2 + 1] = 0;
- kon1++;
- nach2++;
- }
- a = Console.ReadLine().Split();
- if (a[0] == "+")
- {
- Program.deque(secondhalf, 1, int.Parse(a[1]), ref nach2, ref kon2);
- }
- if (a[0] == "*")
- {
- Program.deque(secondhalf, 2, int.Parse(a[1]), ref nach2, ref kon2);
- }
- if (a[0] == "-")
- {
- Console.WriteLine(firsthalf[nach1]);
- nach1++;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement