Advertisement
Guest User

Untitled

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