Advertisement
vov44k

Untitled

Nov 20th, 2022
837
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.05 KB | None | 0 0
  1. import java.io.File;
  2. import java.io.*;
  3. import java.util.*;
  4.  
  5. public class task61 {
  6.     public static class Deqeue {
  7.         static int H = 26000;
  8.         static int T = 26000;
  9.         static int[] arr = new int[100];
  10.         static PrintWriter out;
  11.  
  12.         static void pushFront(int n) {
  13.             arr[T % 100] = n;
  14.             T++;
  15.             out.println("ok");
  16.         }
  17.  
  18.         static void pushBack(int n) {
  19.             H--;
  20.             arr[H % 100] = n;
  21.             out.println("ok");
  22.         }
  23.  
  24.         public static void popFront() {
  25.             if (T - H == 0) {
  26.                 out.println("error");
  27.                 return;
  28.             }
  29.             T--;
  30.             out.println(arr[T % 100]);
  31.         }
  32.  
  33.         public static void popBack() {
  34.             if (T - H == 0) {
  35.                 out.println("error");
  36.                 return;
  37.             }
  38.             int n = arr[H % 100];
  39.             H++;
  40.             out.println(n);
  41.         }
  42.  
  43.         public static void front() {
  44.             if (T - H == 0) {
  45.                 out.println("error");
  46.                 return;
  47.             }
  48.             out.println(arr[(T - 1) % 100]);
  49.         }
  50.  
  51.         public static void back() {
  52.             if (T - H == 0) {
  53.                 out.println("error");
  54.                 return;
  55.             }
  56.             out.println(arr[H % 100]);
  57.         }
  58.  
  59.         public static void size() {
  60.             out.println(Math.abs(T - H));
  61.         }
  62.  
  63.         public static void clear() {
  64.             arr = new int[100];
  65.             H = 26000;
  66.             T = 26000;
  67.             out.println("ok");
  68.         }
  69.  
  70.         public static void exit() {
  71.             out.println("bye");
  72.         }
  73.     }
  74.  
  75.     public static void main(String[] args) throws FileNotFoundException {
  76.         Scanner in = new Scanner(new File("input.txt"));
  77.         out = new PrintWriter(new File("output.txt"));
  78.         while (in.hasNext()) {
  79.             String m = in.next();
  80.             if (m.equals("push_front")) {
  81.                 pushFront(in.nextInt());
  82.                 continue;
  83.             }
  84.             if (m.equals("push_back")) {
  85.                 pushBack(in.nextInt());
  86.                 continue;
  87.             }
  88.             if (m.equals("pop_front")) {
  89.                 popFront();
  90.                 continue;
  91.             }
  92.             if (m.equals("pop_back")) {
  93.                 popBack();
  94.                 continue;
  95.             }
  96.             if (m.equals("front")) {
  97.                 front();
  98.                 continue;
  99.             }
  100.             if (m.equals("back")) {
  101.                 back();
  102.                 continue;
  103.             }
  104.             if (m.equals("size")) {
  105.                 size();
  106.                 continue;
  107.             }
  108.             if (m.equals("clear")) {
  109.                 clear();
  110.                 continue;
  111.             }
  112.             if (m.equals("exit")) {
  113.                 exit();
  114.                 in.close();
  115.                 out.close();
  116.                 return;
  117.             }
  118.         }
  119.         in.close();
  120.         out.close();
  121.     }
  122.  
  123. }
  124.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement