Advertisement
Guest User

Untitled

a guest
Mar 1st, 2015
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.66 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package ppa2_cv_04_2_a14b0537p;
  7.  
  8. import java.util.Arrays;
  9. import java.util.Scanner;
  10.  
  11. /**
  12. *
  13. * @author Milan
  14. */
  15. public class PPA2_cv_04_2_A14B0537P
  16. {
  17. public static char k = 'k';
  18. public static char p = 'p';
  19. public static char o = 'o';
  20. public static char prvni = 'A';
  21. public static char[] fronta = new char[3];
  22. public static int zacatekSeznamu = 0;
  23. public static int konecSeznamu = 0 ;
  24. public static int pocetVeFronte = 0;
  25. /**
  26. * @param args the command line arguments
  27. */
  28. public static void main(String[] args)
  29. {
  30. Scanner sc = new Scanner(System.in);
  31.  
  32. for(int i = 0; true;i++)
  33. {
  34. String vstup = sc.nextLine();
  35. if(vstup.charAt(0)== p)
  36. {
  37.  
  38. fronta[pocetVeFronte] = (prvni);
  39. prvni++;
  40. konecSeznamu++;
  41. System.out.println("dylka pole " + fronta.length + " pocetvefronte " + pocetVeFronte);
  42. pocetVeFronte++;
  43. zmenaPole(fronta);
  44. vypsaniPole();
  45.  
  46.  
  47. }
  48. if(vstup.charAt(0)== o)
  49. {
  50. if(zacatekSeznamu != konecSeznamu)
  51. {
  52. zacatekSeznamu++;
  53. pocetVeFronte--;
  54. posoupnuti();
  55. zmenaPole(fronta);
  56. vypsaniPole();
  57.  
  58. } else
  59. {
  60. break;
  61. }
  62. }
  63. if(zacatekSeznamu==konecSeznamu)
  64. {
  65. System.out.println("Fronta je prazdna");
  66. if(sc.nextLine().charAt(0)==o)
  67. {
  68. System.out.println("Chyba, fronta je prazdna");
  69.  
  70. }
  71. }
  72.  
  73. if(vstup.charAt(0)== k)
  74. {
  75. if(zacatekSeznamu!=konecSeznamu)
  76. {
  77. System.out.println("Ve fronte nekdo zbyl");
  78. }
  79. break;
  80. }
  81.  
  82. }
  83.  
  84. }
  85.  
  86.  
  87. public static void zmenaPole(char[] pole)
  88.  
  89. {
  90.  
  91. if(pocetVeFronte >= fronta.length-1 )
  92. {
  93. System.out.println("dylka pole " + fronta.length + " pocetvefronte " + pocetVeFronte);
  94. char[] tempFronta = new char[(fronta.length * 2)];
  95. System.arraycopy(fronta, 0, tempFronta, 0, fronta.length);
  96. fronta=tempFronta;
  97. }
  98. else if(pocetVeFronte <= 2 * (fronta.length) && pocetVeFronte >= 3 )
  99. {
  100. int novadylka = fronta.length/2 ;
  101. char[] tempFronta = new char[novadylka];
  102. System.arraycopy(fronta, 0, tempFronta, 0, tempFronta.length); // tady dodelat
  103. fronta=tempFronta;
  104. }
  105.  
  106. }
  107. public static void vypsaniPole()
  108. {
  109. String soucasnaFronta="";
  110. for(int i = zacatekSeznamu; i<fronta.length;i++)
  111. {
  112. soucasnaFronta += fronta[i];
  113. }
  114. System.out.println(soucasnaFronta);
  115. }
  116.  
  117. public static void posoupnuti()
  118. {
  119. char[] tempFronta = new char[fronta.length];
  120. System.arraycopy(fronta, 1, tempFronta, 1, fronta.length - 1);
  121. fronta = tempFronta;
  122. }
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement