Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.78 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4.  
  5. /*Na vlez e dadena edna dvojno povrzana lista sostavena od info pole koe e char vrednost.
  6. Da se napravat dve posebni dvojno povrzani listi vo koi vo ednata ke se prefrlat
  7. jazlite koi imaat samoglaska vo nivnata vrednost a vo drugata listata jazlite koi imaat soglaska.
  8.  
  9. 12
  10. pefgsaiudfwq
  11.  
  12. p f g s d f w q
  13. e a i u
  14. */
  15.  
  16. class DLL<E> {
  17. private DLLNode<E> first, last;
  18.  
  19. public DLL() {
  20. // Construct an empty SLL
  21. this.first = null;
  22. this.last = null;
  23. }
  24.  
  25. public void deleteList() {
  26. first = null;
  27. last = null;
  28. }
  29.  
  30. public int length() {
  31. int ret;
  32. if (first != null) {
  33. DLLNode<E> tmp = first;
  34. ret = 1;
  35. while (tmp.succ != null) {
  36. tmp = tmp.succ;
  37. ret++;
  38. }
  39. return ret;
  40. } else
  41. return 0;
  42.  
  43. }
  44.  
  45. public DLLNode<E> find(E o) {
  46. if (first != null) {
  47. DLLNode<E> tmp = first;
  48. while (tmp.element != o && tmp.succ != null)
  49. tmp = tmp.succ;
  50. if (tmp.element == o) {
  51. return tmp;
  52. } else {
  53. System.out.println("Elementot ne postoi vo listata");
  54. }
  55. } else {
  56. System.out.println("Listata e prazna");
  57. }
  58. return first;
  59. }
  60.  
  61. public void insertFirst(E o) {
  62. DLLNode<E> ins = new DLLNode<E>(o, null, first);
  63. if (first == null)
  64. last = ins;
  65. else
  66. first.pred = ins;
  67. first = ins;
  68. }
  69.  
  70. public void insertLast(E o) {
  71. if (first == null)
  72. insertFirst(o);
  73. else {
  74. DLLNode<E> ins = new DLLNode<E>(o, last, null);
  75. last.succ = ins;
  76. last = ins;
  77. }
  78. }
  79.  
  80. public void insertAfter(E o, DLLNode<E> after) {
  81. if (after == last) {
  82. insertLast(o);
  83. return;
  84. }
  85. DLLNode<E> ins = new DLLNode<E>(o, after, after.succ);
  86. after.succ.pred = ins;
  87. after.succ = ins;
  88. }
  89.  
  90. public void insertBefore(E o, DLLNode<E> before) {
  91. if (before == first) {
  92. insertFirst(o);
  93. return;
  94. }
  95. DLLNode<E> ins = new DLLNode<E>(o, before.pred, before);
  96. before.pred.succ = ins;
  97. before.pred = ins;
  98. }
  99.  
  100. public E deleteFirst() {
  101. if (first != null) {
  102. DLLNode<E> tmp = first;
  103. first = first.succ;
  104. if (first != null)
  105. first.pred = null;
  106. if (first == null)
  107. last = null;
  108. return tmp.element;
  109. } else
  110. return null;
  111. }
  112.  
  113. public E deleteLast() {
  114. if (first != null) {
  115. if (first.succ == null)
  116. return deleteFirst();
  117. else {
  118. DLLNode<E> tmp = last;
  119. last = last.pred;
  120. last.succ = null;
  121. return tmp.element;
  122. }
  123. }
  124. // else throw Exception
  125. return null;
  126. }
  127.  
  128. public E delete(DLLNode<E> node) {
  129. if (node == first) {
  130. deleteFirst();
  131. return node.element;
  132. }
  133. if (node == last) {
  134. deleteLast();
  135. return node.element;
  136. }
  137. node.pred.succ = node.succ;
  138. node.succ.pred = node.pred;
  139. return node.element;
  140.  
  141. }
  142.  
  143. @Override
  144. public String toString() {
  145. String ret = new String();
  146. if (first != null) {
  147. DLLNode<E> tmp = first;
  148. ret += tmp + " ";
  149. while (tmp.succ != null) {
  150. tmp = tmp.succ;
  151. ret += tmp + " ";
  152. }
  153. } else
  154. ret = "Prazna lista!!!";
  155. return ret;
  156. }
  157.  
  158. public String toStringR() {
  159. String ret = new String();
  160. if (last != null) {
  161. DLLNode<E> tmp = last;
  162. ret += tmp + "<->";
  163. while (tmp.pred != null) {
  164. tmp = tmp.pred;
  165. ret += tmp + "<->";
  166. }
  167. } else
  168. ret = "Prazna lista!!!";
  169. return ret;
  170. }
  171.  
  172. public DLLNode<E> getFirst() {
  173. return first;
  174. }
  175.  
  176. public DLLNode<E> getLast() {
  177.  
  178. return last;
  179. }
  180.  
  181. public void izvadiDupliIPrebroj() {
  182.  
  183. }
  184. }
  185.  
  186. class DLLNode<E> {
  187. protected E element;
  188. protected DLLNode<E> pred, succ;
  189.  
  190. public DLLNode(E elem, DLLNode<E> pred, DLLNode<E> succ) {
  191. this.element = elem;
  192. this.pred = pred;
  193. this.succ = succ;
  194. }
  195.  
  196. @Override
  197. public String toString() {
  198. return element.toString();
  199. }
  200. }
  201.  
  202. public class Test {
  203.  
  204. public static void main(String[] args) throws NumberFormatException, IOException {
  205. BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  206. DLL<Character> lista = new DLL<Character>();
  207. DLL<Character> samoglaski = new DLL<Character>();
  208. DLL<Character> soglaski = new DLL<Character>();
  209.  
  210. int N = Integer.parseInt(br.readLine());
  211. String[] pom = br.readLine().split("");
  212. for (int i = 0; i < N; i++) {
  213. lista.insertLast(pom[i].charAt(0));
  214. }
  215. DLLNode<Character> dvizhi = lista.getFirst();
  216. while (dvizhi != null) {
  217. if (String.valueOf(dvizhi.element).equals("a") || String.valueOf(dvizhi.element).equals("e")
  218. || String.valueOf(dvizhi.element).equals("i") || String.valueOf(dvizhi.element).equals("o")
  219. || String.valueOf(dvizhi.element).equals("u")) {
  220. samoglaski.insertLast(dvizhi.element);
  221. } else {
  222. soglaski.insertLast(dvizhi.element);
  223. }
  224. dvizhi = dvizhi.succ;
  225. }
  226. System.out.println(soglaski);
  227. System.out.println(samoglaski);
  228. }
  229.  
  230. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement