How to submit code to that shit site?

This Java code seems to work, but I don't know how to submit there:
package org.onlinejudge.uva;

import java.io.File;
import java.io.PrintWriter;
import java.util.Scanner;

public class ATheTrip
{
    static Scanner in;
    static PrintWriter out;

    public static void main(String[] args) throws Exception {
        in = new Scanner(new File("src/org/onlinejudge/uva/sample.txt"));
        out = new PrintWriter(new
File("src/org/onlinejudge/uva/sample-output.txt"));

        int T = in.nextInt();
        while(T > 0) {
            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;
            }

            String sNetCost = "" + netCost;
            int dot = sNetCost.indexOf('.');
            String decimalPart = sNetCost.substring(0, dot);
            String fractionPart = sNetCost.substring(dot+1,
sNetCost.length()-1);
            if(fractionPart.length() == 0) fractionPart = "00";
            else fractionPart = fractionPart.substring(0, 2);
            out.printf("$%s.%s\n", decimalPart, fractionPart);

            T = in.nextInt();
        }
        in.close();
        out.close();
    }
}


On Mon, Oct 10, 2011 at 9:07 AM, yedtoss <[email protected]> wrote:

> Hi everybody. I am trying to solve the problem id 10137 on UVA online:
>
>
> http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=29&page=show_problem&problem=1078
>
> It is asked to give the amount of money exchanged so that every
> student has the same money (within a cent: 0.01)
>
> Input: n:number of student then n lines each containing the amount in
> dollars and cent spent by a student
> Output: a line stating the total amount of money, in dollars and
> cents, that must be exchanged to equalize the students' costs( within
> a cent).
>
> Sample  Input:
> 4
> 15.00
> 15.01
> 3.00
> 3.01
>
> Sample Output:
> $11.99
>
> Here is my C++ program
>
> // START
>
> #include <iostream>
> using namespace std;
> long int exec(long int *tab,long int n);
> int main() {
>        long int n=0;
>        double *tab;
>        long int *tab1;
>        while(1)
>        {
>                cin>>n;
>                if(n==0)
>                        break;
>                else
>                {
>                        tab1=new long int[n];
>                        tab=new double[n];
>                        for(int i=0;i<n;i++)
>                        {
>                                // take the input as double
>                                // then multiply it by 100
>                                // and convert to long int
>                                cin>>tab[i];
>                                tab1[i]=100*tab[i];
>                        }
>                        // print result
>                        double ans=exec(tab1,n)/100.0;
>                        cout<<"$"<<ans<<endl;
>
>                }
>
>        }
>
>        return 0;
> }
> // To calculate the total amount exchanged
> // Every amount is multiplied by 100
> long int exec(long int *tab,long int n)
> {
>        long int sum=0,sum1=0,number1=0,number=0,diff=0;
>        // The amount(goal) every student will have is the sum of all
>        // amount divided by the number of students.
>
>        for(int i=0;i<n;i++)
>                sum+=tab[i];
>        long int goal=sum/n,goal1=goal;
>        // If  sum/n is not an integer then the amount could
>        // also be goal+1
>        // "number" is the total number of students who will have
>        // goal+1
>        if(sum%n!=0)
>        {
>        number=sum-goal*n;
>        goal1=goal+1;
>        }
>        // The total amount exchanged is the (minimal) difference
>        // between all students costs (so that their cost is high than goal)
>        // and their new costs((goal+1)*number+goal*(number1-number))
>        // number1 is the total number of students(H) so that their cost
>        // are high than goal
>        // sum1 is the total costs of students H
>        for(int i=0;i<n;i++)
>        {
>                if(tab[i]>goal)
>                {
>                        sum1+=tab[i];
>                        number1++;
>
>                }
>
>        }
>
>        if(number<number1)
>                diff=number1-number;
>        if(number>number1)
>                number=number1;
>        return sum1-(goal1)*number-(goal*diff);
>
>
>
> }
> // END
>
>
> But Iam always getting WRONG ANSWER. I don't know where I am wrong.
>
> Thanks for your help.
>
> --
> 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.

Reply via email to