Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package np;
- import java.util.*;
- public class GoldenBallTest {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- GoldenBall goldenBall = new GoldenBall();
- while (scanner.hasNextLine()) {
- String line = scanner.nextLine();
- if (line == null || line.isEmpty()) break;
- String[] players = line.split(";");
- goldenBall.addVote(players);
- }
- scanner.close();
- System.out.println("===== TOP 10 ======");
- goldenBall.listTopN(10);
- System.out.println("===== MAX 1 PLACE =====");
- goldenBall.maxPlace(1);
- System.out.println("===== MAX 2 PLACE =====");
- goldenBall.maxPlace(2);
- System.out.println("===== MAX 3 PLACE =====");
- goldenBall.maxPlace(3);
- System.out.println("===== COUNT =====");
- goldenBall.count();
- }
- }
- class Player
- {
- String name;
- int poeni;
- int c1;
- int c2;
- int c3;
- static int max = 0;
- public Player(String name)
- {
- this.name = name;
- poeni = 0;
- c1 = 0;
- c2 = 0;
- c3 = 0;
- }
- public double procent()
- {
- return poeni / (max * 5);
- }
- public void prvo()
- {
- poeni += 5;
- c1++;
- }
- public void vtoro()
- {
- poeni += 3;
- c2++;
- }
- public void treto()
- {
- poeni += 1;
- c3++;
- }
- }
- class GoldenBall
- {
- Map<String , Player> nominees;
- public GoldenBall()
- {
- this.nominees = new TreeMap<>();
- }
- public void addVote(String[] players) {
- if(!nominees.containsKey(players[0]))
- {
- Player n = new Player(players[0]);
- n.prvo();
- nominees.put(players[0] , n );
- }
- else
- {
- Player n = nominees.get(players[0]);
- n.prvo();
- }
- if(!nominees.containsKey(players[1]))
- {
- Player n = new Player(players[1]);
- n.vtoro();
- nominees.put(players[1] , n );
- }
- else
- {
- Player n = nominees.get(players[1]);
- n.vtoro();
- }
- if(!nominees.containsKey(players[2]))
- {
- Player n = new Player(players[2]);
- n.treto();
- nominees.put(players[2] , n );
- }
- else
- {
- Player n = nominees.get(players[2]);
- n.treto();
- }
- Player.max++;
- }
- public void listTopN(int n) {
- List<Player> toplist = new ArrayList<>();
- for(String s : nominees.keySet())
- {
- toplist.add(nominees.get(s));
- }
- int i = 0;
- Collections.sort(toplist , new CustomComp());
- Iterator<Player> it = toplist.iterator();
- while(it.hasNext() && i < n )
- {
- Player p = it.next();
- System.out.println(String.format("%d . %s %d %.3f %" , (i+1) , p.name , p.poeni , p.procent()));
- }
- }
- public void maxPlace(int i) {
- if(i == 1)
- {
- int max = 0;
- String tmp = "";
- for(String s : nominees.keySet())
- {
- if(nominees.get(s).c1 >= max)
- {
- max = nominees.get(s).c1;
- tmp = s;
- }
- }
- System.out.println(String.format("%s ", tmp));
- }
- else if(i == 2)
- {
- int max = 0;
- String tmp = "";
- for(String s : nominees.keySet())
- {
- if(nominees.get(s).c2 >= max)
- {
- max = nominees.get(s).c1;
- tmp = s;
- }
- }
- System.out.println(String.format("%s ", tmp));
- }
- else if (i == 3)
- {
- int max = 0;
- String tmp = "";
- for(String s : nominees.keySet())
- {
- if(nominees.get(s).c3 >= max)
- {
- max = nominees.get(s).c1;
- tmp = s;
- }
- }
- System.out.println(String.format("%s ", tmp));
- }
- }
- public void count() {
- }
- }
- class CustomComp implements Comparator<Player>
- {
- @Override
- public int compare(Player p1, Player p2) {
- int n1 = p1.poeni;
- int n2 = p2.poeni;
- if(n1 == n2) return p1.name.compareTo(p2.name);
- else return Integer.compare(n1, n2);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement