Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.ArrayList;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- int n = sc.nextInt();
- ArrayList<String> votes = new ArrayList<>();
- for(int i=0;i<n;i++){
- String vote = sc.next();
- votes.add(vote);
- }
- String winner = votesCount(votes, n);
- System.out.println(winner);
- }
- public static String votesCount(ArrayList<String> votes, int n){
- int res = 0;
- int count = 1;
- for(int i=1 ; i < n; i++){
- if(votes.get(i).equals(votes.get(res)))
- count++;
- else{
- count--;
- if(count == 0){
- count = 1;
- res = i;
- }
- }
- }
- count = 0;
- for(String vote : votes)
- if(vote.equals(votes.get(res)))
- count++;
- if(count > n/2)
- return votes.get(res);
- return "DRAW";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement