Advertisement
Guest User

Untitled

a guest
May 24th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.43 KB | None | 0 0
  1. //package masodikzh;
  2.  
  3. import java.io.File;
  4. import java.io.FileNotFoundException;
  5. import java.util.ArrayList;
  6. import java.util.Scanner;
  7.  
  8. class Tura {
  9.  
  10.     String tura;
  11.     String nev;
  12.     int db;
  13.  
  14.     public Tura(String tura, String nev) {
  15.         this.tura = tura;
  16.         this.nev = nev;
  17.     }
  18. }
  19.  
  20. class Szemely implements Comparable<Szemely>{
  21.  
  22.     String nev;
  23.  
  24.     public Szemely(String nev) {
  25.         this.nev = nev;
  26.     }
  27.  
  28.     @Override
  29.     public int compareTo(Szemely o) {
  30.         return this.nev.compareTo(o.nev);
  31.     }
  32.  
  33. }
  34.  
  35. public class C_D_feladat {
  36.  
  37.     public static void main(String[] args) throws FileNotFoundException {
  38.         File f = new File(args[0]);
  39.         Scanner sc = new Scanner(f);
  40.         ArrayList<Tura> lista = new ArrayList<Tura>();
  41.         ArrayList<Szemely> nevLista = new ArrayList<Szemely>();
  42.         int max = 0;
  43.  
  44.         while (sc.hasNextLine()) {
  45.             String sor = sc.nextLine();
  46.             if (sor.equals("e")) {
  47.                 break;
  48.             }
  49.             String[] st = sor.split("[:;]");
  50.             String tura = st[0];
  51.             for (int i = 1; i < st.length; i++) {
  52.                 String nev = st[i];
  53.                 lista.add(new Tura(tura, nev));
  54.             }
  55.         }
  56.  
  57.         for (int i = 0; i < lista.size(); i++) {
  58.             for (int j = 0; j < lista.size(); j++) {
  59.                 if (lista.get(i).nev.equals(lista.get(j).nev)) {
  60.                     lista.get(i).db++;
  61.                 }
  62.             }
  63.             if (lista.get(i).db > max) {
  64.                 max = lista.get(i).db;
  65.             }
  66.         }
  67.  
  68.         int x = 0;
  69.  
  70.         for (int i = 0; i < lista.size(); i++) {
  71.             int van = 0;
  72.             if (lista.get(i).db == max) {
  73.                 if (x == 0) {
  74.                     nevLista.add(new Szemely(lista.get(i).nev));
  75.                     x++;
  76.                 } else {
  77.                     for (int j = 0; j < nevLista.size(); j++) {
  78.                         if (nevLista.get(j).nev.equals(lista.get(i).nev)) {
  79.                             van++;
  80.                         }
  81.                     }
  82.                    
  83.                     if(van == 0){
  84.                         nevLista.add(new Szemely(lista.get(i).nev));
  85.                     }
  86.  
  87.                 }
  88.             }
  89.         }
  90.        
  91.         for (int i = 0; i < nevLista.size(); i++) {
  92.             System.out.println(nevLista.get(i).nev);
  93.         }
  94.     }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement