Martina312

Компанија

Nov 19th, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.00 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4.  
  5.  
  6.  
  7. class SLLNode {
  8. protected int id;
  9. protected int plata;
  10. protected SLLNode succ;
  11.  
  12. public SLLNode(int id,int plata, SLLNode succ) {
  13. this.id = id;
  14. this.plata=plata;
  15. this.succ = succ;
  16. }
  17.  
  18.  
  19. }
  20.  
  21. class SLL {
  22. private SLLNode first;
  23.  
  24. public SLL() {
  25. // Construct an empty SLL
  26. this.first = null;
  27. }
  28.  
  29. public void deleteList() {
  30. first = null;
  31. }
  32.  
  33. public int length() {
  34. int ret;
  35. if (first != null) {
  36. SLLNode tmp = first;
  37. ret = 1;
  38. while (tmp.succ != null) {
  39. tmp = tmp.succ;
  40. ret++;
  41. }
  42. return ret;
  43. } else
  44. return 0;
  45.  
  46. }
  47.  
  48.  
  49. public void insertFirst(int id, int plata) {
  50. SLLNode ins = new SLLNode(id,plata, first);
  51. first = ins;
  52. }
  53.  
  54. public void insertLast(int id,int plata) {
  55. if (first != null) {
  56. SLLNode tmp = first;
  57. while (tmp.succ != null)
  58. tmp = tmp.succ;
  59. SLLNode ins = new SLLNode(id, plata, null);
  60. tmp.succ = ins;
  61. } else {
  62. insertFirst(id,plata);
  63. }
  64. }
  65.  
  66. public SLLNode getFirst() {
  67. return first;
  68. }
  69.  
  70.  
  71. public SLL brisi_pomali_od(int iznos) {
  72. // Vasiot kod tuka
  73. /* SLL rezultat=new SLL();
  74. SLLNode tmp=first;
  75.  
  76. while(tmp!=null){
  77. if(tmp.plata>=iznos){
  78. rezultat.insertLast(tmp.id,tmp.plata);
  79. }
  80. tmp=tmp.succ;
  81. }
  82. return rezultat;*/
  83.  
  84. SLLNode tmp=this.first;
  85. while(tmp!=null){
  86. if(tmp.plata<iznos){
  87. if(tmp==first){
  88. tmp=tmp.succ;
  89. first=first.succ;
  90. }
  91. else if(tmp.succ==null){
  92. SLLNode tmp2=first;
  93. while(tmp2.succ!=tmp){
  94. tmp2=tmp2.succ;
  95. }
  96. if(tmp2.succ==tmp) {
  97. tmp2.succ = null;
  98. tmp = null;
  99. }
  100. }
  101. else{
  102. SLLNode tmp2=first;
  103. while(tmp2.succ!=tmp){
  104. tmp2=tmp2.succ;
  105. }
  106. if(tmp2.succ==tmp){
  107. tmp2.succ=tmp.succ;
  108. tmp=tmp2.succ;
  109. }
  110. }
  111. }
  112. else{
  113. tmp=tmp.succ;
  114. }
  115.  
  116. }
  117. return this;
  118. }
  119.  
  120. public SLL sortiraj_opagacki() {
  121. // Vasiot kod tuka
  122. SLL rezultat=new SLL();
  123. rezultat=this;
  124. SLLNode tmp=rezultat.first;
  125. SLLNode tmp2;
  126. while(tmp!=null){
  127. tmp2=tmp.succ;
  128. while(tmp2!=null){
  129. if(tmp.id <= tmp2.id){
  130. int tmpP=tmp.plata;
  131. tmp.plata=tmp2.plata;
  132. tmp2.plata=tmpP;
  133.  
  134. int tmpI=tmp.id;
  135. tmp.id=tmp2.id;
  136. tmp2.id=tmpI;
  137. }
  138. tmp2=tmp2.succ;
  139. }
  140. tmp=tmp.succ;
  141. }
  142. return rezultat;
  143.  
  144. }
  145. public void pecati (SLL lista)
  146. {
  147. SLLNode p=lista.first;
  148. while(p!=null)
  149. {
  150. System.out.println(p.id+" "+p.plata);
  151. p=p.succ;
  152. }
  153. }
  154.  
  155. }
  156. public class SLLKompanija {
  157. public static void main(String[] args) throws IOException {
  158.  
  159. SLL lista1 = new SLL();
  160. BufferedReader stdin = new BufferedReader(new InputStreamReader(
  161. System.in));
  162. String s = stdin.readLine();
  163. int N = Integer.parseInt(s);
  164.  
  165. for (int i = 0; i < N; i++) {
  166. s=stdin.readLine();
  167. String s1=stdin.readLine();
  168. lista1.insertLast(Integer.parseInt(s),Integer.parseInt(s1));
  169. }
  170. s = stdin.readLine();
  171.  
  172. lista1=lista1.brisi_pomali_od(Integer.parseInt(s));
  173. if(lista1.getFirst()!=null)
  174. {
  175. lista1=lista1.sortiraj_opagacki();
  176. lista1.pecati(lista1);
  177. }
  178. else{
  179. System.out.println("nema");
  180. }
  181.  
  182. }
  183. }
Add Comment
Please, Sign In to add comment