Advertisement
Guest User

Untitled

a guest
Oct 20th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1.  
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5. import java.util.Scanner;
  6.  
  7. class Nev{
  8. public String nev;
  9. public String elotte;
  10. public String utana;
  11.  
  12. public Nev(String nev, String elotte, String utana) {
  13. this.nev = nev;
  14. this.elotte = elotte;
  15. this.utana = utana;
  16. }
  17.  
  18. public String getNev() {
  19. return nev;
  20. }
  21.  
  22. public void setNev(String nev) {
  23. this.nev = nev;
  24. }
  25.  
  26. public String getElotte() {
  27. return elotte;
  28. }
  29.  
  30. public void setElotte(String elotte) {
  31. this.elotte = elotte;
  32. }
  33.  
  34. public String getUtana() {
  35. return utana;
  36. }
  37.  
  38. public void setUtana(String utana) {
  39. this.utana = utana;
  40. }
  41.  
  42. @Override
  43. public String toString() {
  44. return "Nev{" + "nev=" + nev + ", elotte=" + elotte + ", utana=" + utana + '}';
  45. }
  46.  
  47.  
  48. }
  49.  
  50. public class Tornasor {
  51.  
  52. public static void main(String[] args) {
  53. Scanner sc = new Scanner(System.in);
  54. List<Nev> list = new ArrayList<>();
  55. List<String> list2 = new ArrayList<>();
  56. String[] token;
  57.  
  58. int n = sc.nextInt();
  59. sc.nextLine();
  60. String elso_sor = sc.nextLine();
  61. list2.add(elso_sor);
  62. for (int i=0; i<n-1; i++)
  63. {
  64. String lines = sc.nextLine();
  65. token = lines.split(";");
  66. if (token.length == 3)
  67. list.add(new Nev(token[0], token[1], token[2]));
  68. else if (token.length == 2)
  69. list.add(new Nev(token[0], token[1], null));
  70. }
  71. // System.out.println(elso_sor);
  72. int j=0;
  73. for (int x=0; x<n; x++)
  74. {
  75. for (int i=0; i<n-1; i++)
  76. {
  77. if (list.get(i).elotte.equals(list2.get(j)))
  78. {
  79. list2.add(list.get(i).nev);
  80. j++;
  81. }
  82. }
  83. }
  84. for (int i=0; i<list2.size(); i++)
  85. {
  86. System.out.println(list2.get(i));
  87. }
  88. }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement