Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package ppa2_cv_04_2_a14b0537p;
- import java.util.Arrays;
- import java.util.Scanner;
- /**
- *
- * @author Milan
- */
- public class PPA2_cv_04_2_A14B0537P
- {
- public static char k = 'k';
- public static char p = 'p';
- public static char o = 'o';
- public static char prvni = 'A';
- public static char[] fronta = new char[3];
- public static int zacatekSeznamu = 0;
- public static int konecSeznamu = 0 ;
- public static int pocetVeFronte = 0;
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args)
- {
- Scanner sc = new Scanner(System.in);
- for(int i = 0; true;i++)
- {
- String vstup = sc.nextLine();
- if(vstup.charAt(0)== p)
- {
- fronta[pocetVeFronte] = (prvni);
- prvni++;
- konecSeznamu++;
- System.out.println("dylka pole " + fronta.length + " pocetvefronte " + pocetVeFronte);
- pocetVeFronte++;
- zmenaPole(fronta);
- vypsaniPole();
- }
- if(vstup.charAt(0)== o)
- {
- if(zacatekSeznamu != konecSeznamu)
- {
- zacatekSeznamu++;
- pocetVeFronte--;
- posoupnuti();
- zmenaPole(fronta);
- vypsaniPole();
- } else
- {
- break;
- }
- }
- if(zacatekSeznamu==konecSeznamu)
- {
- System.out.println("Fronta je prazdna");
- if(sc.nextLine().charAt(0)==o)
- {
- System.out.println("Chyba, fronta je prazdna");
- }
- }
- if(vstup.charAt(0)== k)
- {
- if(zacatekSeznamu!=konecSeznamu)
- {
- System.out.println("Ve fronte nekdo zbyl");
- }
- break;
- }
- }
- }
- public static void zmenaPole(char[] pole)
- {
- if(pocetVeFronte >= fronta.length-1 )
- {
- System.out.println("dylka pole " + fronta.length + " pocetvefronte " + pocetVeFronte);
- char[] tempFronta = new char[(fronta.length * 2)];
- System.arraycopy(fronta, 0, tempFronta, 0, fronta.length);
- fronta=tempFronta;
- }
- else if(pocetVeFronte <= 2 * (fronta.length) && pocetVeFronte >= 3 )
- {
- int novadylka = fronta.length/2 ;
- char[] tempFronta = new char[novadylka];
- System.arraycopy(fronta, 0, tempFronta, 0, tempFronta.length); // tady dodelat
- fronta=tempFronta;
- }
- }
- public static void vypsaniPole()
- {
- String soucasnaFronta="";
- for(int i = zacatekSeznamu; i<fronta.length;i++)
- {
- soucasnaFronta += fronta[i];
- }
- System.out.println(soucasnaFronta);
- }
- public static void posoupnuti()
- {
- char[] tempFronta = new char[fronta.length];
- System.arraycopy(fronta, 1, tempFronta, 1, fronta.length - 1);
- fronta = tempFronta;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement