Contest 9

All contest related discussion goes here. Both Dev Skill and Non Dev Skill contest related discussion is allowed. (But please keep the forum clean)

Contest 9

by arabin » Sat Sep 03, 2016 10:44 pm

In tonights contest i have submitted the code given below for the problem number 1. but it was a wrong answer i dont know why? can anyone help me to solve this. i dont understand where is the problem.

Code: Select all
class MyClass {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws java.lang.Exception{
        // TODO code application logic here
       
        Scanner kbScanner = new Scanner(System.in);
        int test = kbScanner.nextInt();
       
        if (test>=1&&test<=1000) {
            double []answer = new double[test];
            for (int i = 0; i < test; i++) {
                answer[i] = calculate(kbScanner.nextInt(),kbScanner.nextInt());
            }
           
            for (int i = 0; i < answer.length; i++) {
                System.out.println("Case "+(i+1)+":"+" "+(int)answer[i]);
            }
           
        }
       
    }

    private static double calculate(int next, int next0) {
           
      return Math.pow((2*next),2)-Math.pow(next0,2);
   
    }
   
}
 
Posts: 28
Joined: Sat Aug 06, 2016 11:02 pm

Re: Contest 9

by froghramar » Sun Sep 04, 2016 12:03 am

It is not guaranteed that the answer will fit into an integer. Use Long in java. When you are printing the solution just type cast it to Long instead of int. I think it will make sure your program gets accepted.
User avatar
 
Posts: 33
Joined: Thu Jul 28, 2016 8:14 am
Location: Amar Ekushey Hall, University of Dhaka

Re: Contest 9

by arabin » Sun Sep 04, 2016 12:26 am

yap i got it. thank you :)
 
Posts: 28
Joined: Sat Aug 06, 2016 11:02 pm

Re: Contest 9

by devskill » Thu Sep 15, 2016 10:22 pm

@Myersrab

Contest 9 is over. This is Dev skill forum. visit: www.devskill.com for list of upcoming and running contests. There you will find all detail about when contest starts and how to register.
User avatar
Site Admin
 
Posts: 118
Joined: Tue Feb 02, 2016 10:24 pm


Who is online
Users browsing this forum: No registered users and 1 guest
cron