Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //package masodikzh;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.util.ArrayList;
- import java.util.Scanner;
- class Tura {
- String tura;
- String nev;
- int db;
- public Tura(String tura, String nev) {
- this.tura = tura;
- this.nev = nev;
- }
- }
- class Szemely implements Comparable<Szemely>{
- String nev;
- public Szemely(String nev) {
- this.nev = nev;
- }
- @Override
- public int compareTo(Szemely o) {
- return this.nev.compareTo(o.nev);
- }
- }
- public class C_D_feladat {
- public static void main(String[] args) throws FileNotFoundException {
- File f = new File(args[0]);
- Scanner sc = new Scanner(f);
- ArrayList<Tura> lista = new ArrayList<Tura>();
- ArrayList<Szemely> nevLista = new ArrayList<Szemely>();
- int max = 0;
- while (sc.hasNextLine()) {
- String sor = sc.nextLine();
- if (sor.equals("e")) {
- break;
- }
- String[] st = sor.split("[:;]");
- String tura = st[0];
- for (int i = 1; i < st.length; i++) {
- String nev = st[i];
- lista.add(new Tura(tura, nev));
- }
- }
- for (int i = 0; i < lista.size(); i++) {
- for (int j = 0; j < lista.size(); j++) {
- if (lista.get(i).nev.equals(lista.get(j).nev)) {
- lista.get(i).db++;
- }
- }
- if (lista.get(i).db > max) {
- max = lista.get(i).db;
- }
- }
- int x = 0;
- for (int i = 0; i < lista.size(); i++) {
- int van = 0;
- if (lista.get(i).db == max) {
- if (x == 0) {
- nevLista.add(new Szemely(lista.get(i).nev));
- x++;
- } else {
- for (int j = 0; j < nevLista.size(); j++) {
- if (nevLista.get(j).nev.equals(lista.get(i).nev)) {
- van++;
- }
- }
- if(van == 0){
- nevLista.add(new Szemely(lista.get(i).nev));
- }
- }
- }
- }
- for (int i = 0; i < nevLista.size(); i++) {
- System.out.println(nevLista.get(i).nev);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement