Thanksss!!! It is working. my solution is ACCEPTED by changing 100*tab[i]; by 100*tab[i]+0.5;
I should be more careful now with the type double.... To submit your code you should register to UVA website. Then you go on this link (The link of the problem) http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=29&page=show_problem&problem=1078 Then you click Submit Button (on top of the problem). You choose your language (Java). You can paste your code or Click Browse to load the source file and then click Submit. you will receive an email to see the results or you can go to MySubmissions ( menu on the left side ). On Oct 12, 4:21 pm, Luke Pebody <[email protected]> wrote: > You have rounding errors when you multiply by 100. > > double x = 0.03; > int y = x * 100; > > y is equal to 2. Seehttp://www.ideone.com/DXGZm > On 11 Oct 2011 19:25, "yedtoss" <[email protected]> wrote: > > > > > > > > > I ran my program against yours with a few inputs and we get the same > > results. I will try to generate random numbers to check if you have > > the same results. > > > But I have noticed something interesting: they are using gcc 4.4.5 > > version and I am using 4.5.2. > > > I think that some functions behave differently with this two versions. > > For example int abs(int) doesn't work on 4.4.5 but on 4.5.2 > > > But I don't know exactly where the problem is. > > > On Oct 10, 9:39 pm, tivrfoa <[email protected]> wrote: > > > 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&... > > > > 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. -- 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.
