My solution works for the sample, but when I submit it shows wrong answer. I'll never know what's wrong if they don't provide a bigger input and output to test.
Problem: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=29&problem=1078 My Java solution: import java.util.Scanner; class Main { static Scanner in = new Scanner(System.in); public static void main(String[] args) throws Exception { int T = in.nextInt(); while(true) { double sum = 0; double netCost = 0; double[] costs = new double[T]; for(int i = 0; i < T; i++) { costs[i] = in.nextDouble(); sum += costs[i]; } double ma = sum/T; for(int i = 0; i < T; i++) { double x = ma - costs[i]; if(x > 0) netCost += x; } System.out.printf("$%.2f", round2(netCost)); T = in.nextInt(); if(T > 0) System.out.println(); else break; } System.exit(0); } public static double round2(double num) { String sNum = "" + num; int dot = sNum.indexOf('.'); String decimalPart = sNum.substring(0, dot); String fractionPart = sNum.substring(dot+1, sNum.length()-1); if(fractionPart.length() == 0) fractionPart = "00"; else fractionPart = fractionPart.substring(0, 2); return Double.parseDouble(decimalPart + "." + fractionPart); } } -- You received this message because you are subscribed to the Google Groups "google-codejam" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-code?hl=en.
