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