Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company
- import java.util.*
- fun main() {
- val sc = Scanner(System.`in`)
- val n = sc.nextInt()
- val votes = ArrayList<String>()
- for (i in 0 until n) {
- val vote = sc.next()
- votes.add(vote)
- }
- val winner = votesCount(votes, n)
- println(winner)
- }
- fun votesCount(votes: ArrayList<String>, n: Int): String {
- var res = 0
- var count = 1
- for (i in 1 until n) {
- if (votes[i] == votes[res]) count++ else {
- count--
- if (count == 0) {
- count = 1
- res = i
- }
- }
- }
- count = 0
- for (vote in votes) if (vote == votes[res]) count++
- return if (count > n / 2) votes[res] else "DRAW"
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement