ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1263. Elections

№12 Pls help. What's wrong with my code? Java
Posted by Vladimir 26 Jul 2015 16:13
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Scanner;


 public class main
 {

 public static Scanner in = new Scanner(System.in);

 public static void main(String[] args)
 {
   int candidates = in.nextInt();
   int electors = in.nextInt();
   int votes[] = new int[electors];
   int summ = 0;
   double onePercent = (double) electors / 100;

   for(int x = 0; x < electors; x++)
   {
     votes[x] = in.nextInt();
   }

   Arrays.sort(votes);
   int VoteNum = 1;
   int startOfNextSearch = 0;

   while(candidates != 0)
   {
   for(int x = startOfNextSearch; x < electors; x++)
   {
    if(x > startOfNextSearch && votes[x] == votes[x -1] && votes[x] == VoteNum)
    {
      summ++;
    }
    else if(votes[x] == VoteNum)
    {
    summ++;
    }
    else
    {
    x = electors;
    }
    }
    BigDecimal  Part = new BigDecimal(Double.toString((double) summ / onePercent));
    Part = Part.setScale(2, BigDecimal.ROUND_HALF_UP);
    if((Part.doubleValue() + 1) % 1 == 0)
    {
      System.out.println(Part.doubleValue() + "0%");
    }
    else
    {
      System.out.println(Part.doubleValue() + "%");
    }
    VoteNum++;
    startOfNextSearch += summ ;
    summ = 0;
    candidates--;
    }

  }
}


Edited by author 26.07.2015 16:16