Advertisement
Guest User

Untitled

a guest
Feb 28th, 2015
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.45 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[konecSeznamu] = (prvni);
  39. prvni++;
  40. konecSeznamu++;
  41. pocetVeFronte++;
  42. zmenaPole();
  43.  
  44.  
  45. vypsaniPole();
  46.  
  47. }
  48. if(vstup.charAt(0)== o)
  49. {
  50. if(zacatekSeznamu != konecSeznamu)
  51. {
  52. zacatekSeznamu++;
  53. pocetVeFronte--;
  54. posoupnuti();
  55. zmenaPole();
  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()
  88.  
  89. {
  90.  
  91. if(pocetVeFronte >= fronta.length )
  92. {
  93. char[] tempFronta = new char[fronta.length * 2];
  94. System.arraycopy(fronta, 0, tempFronta, 0, fronta.length);
  95. fronta=tempFronta;
  96. }
  97. if(pocetVeFronte <= 2 * (fronta.length) && pocetVeFronte >= 3 )
  98. {
  99. int novadylka = fronta.length/2 ;
  100. char[] tempFronta = new char[novadylka];
  101. System.arraycopy(fronta, 0, tempFronta, 0, tempFronta.length); // tady dodelat
  102. fronta=tempFronta;
  103. }
  104.  
  105. }
  106. public static void vypsaniPole()
  107. {
  108. String soucasnaFronta="";
  109. for(int i = zacatekSeznamu; i<fronta.length;i++)
  110. {
  111. soucasnaFronta += fronta[i];
  112. }
  113. System.out.println(soucasnaFronta);
  114. }
  115.  
  116. public static void posoupnuti()
  117. {
  118. char[] tempFronta = new char[fronta.length];
  119. System.arraycopy(fronta, 1, tempFronta, 1, fronta.length - 1);
  120. fronta = tempFronta;
  121. }
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement