Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.*;
- public class Main {
- static PrintWriter out;
- public static class Dequeue {
- static int H, T;
- static int[] arr;
- public Dequeue() {
- H = 26000;
- T = 26000;
- arr = new int[100];
- }
- void pushFront(int n) {
- arr[T % 100] = n;
- T++;
- out.println("ok");
- }
- void pushBack(int n) {
- H--;
- arr[H % 100] = n;
- out.println("ok");
- }
- static void popFront() {
- if (T - H == 0) {
- out.println("error");
- return;
- }
- T--;
- out.println(arr[T % 100]);
- }
- static void popBack() {
- if (T - H == 0) {
- out.println("error");
- return;
- }
- int n = arr[H % 100];
- H++;
- out.println(n);
- }
- static void front() {
- if (T - H == 0) {
- out.println("error");
- return;
- }
- out.println(arr[(T - 1) % 100]);
- }
- static void back() {
- if (T - H == 0) {
- out.println("error");
- return;
- }
- out.println(arr[H % 100]);
- }
- static void size() {
- out.println(Math.abs(T - H));
- }
- static void clear() {
- arr = new int[100];
- H = 26000;
- T = 26000;
- out.println("ok");
- }
- static void exit() {
- out.println("bye");
- }
- }
- public static void main(String[] args) throws FileNotFoundException {
- Scanner in = new Scanner(new File("input.txt"));
- out = new PrintWriter("output.txt");
- Dequeue d = new Dequeue();
- while (in.hasNext()) {
- String m = in.next();
- if (m.equals("push_front")) {
- d.pushFront(in.nextInt());
- continue;
- }
- if (m.equals("push_back")) {
- d.pushBack(in.nextInt());
- continue;
- }
- if (m.equals("pop_front")) {
- d.popFront();
- continue;
- }
- if (m.equals("pop_back")) {
- d.popBack();
- continue;
- }
- if (m.equals("front")) {
- d.front();
- continue;
- }
- if (m.equals("back")) {
- d.back();
- continue;
- }
- if (m.equals("size")) {
- d.size();
- continue;
- }
- if (m.equals("clear")) {
- d.clear();
- continue;
- }
- if (m.equals("exit")) {
- d.exit();
- in.close();
- out.close();
- return;
- }
- }
- in.close();
- out.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement