2 / 2
Jun 2018

Hi.
I started 3 days ago doing tasks in Polish Spoj. And today i got such a annoying problem. I cant complete some tasks with Java becouse of compiling time. For example, there is a task when you have to calculate avarage speed. Imo this is the simplest way but its still too long:

    Scanner scanner = new Scanner(System.in);
    int n = scanner.nextInt();
    while(n-->0){
        int v1 = scanner.nextInt();
        int v2 = scanner.nextInt();
        System.out.println((2*v1*v2)/(v1+v2));
    }

When this in c++ passed with colours:
int v1,v2;
cin>>howMuch;
for (int i=1; i<=howMuch; i++)
{
cin>>v1>>v2;
cout<<2*v1*v2/(v1+v2)<<endl;
}
This is polish version: http://pl.spoj.com/problems/VSR/10

  • created

    Aug '17
  • last reply

    Jun '18
  • 1

    reply

  • 1.0k

    views

  • 2

    users

  • 2

    likes

  • 1

    link

10 months later

You should use Java.io.BufferedReader instead of Scanner for fast input/output.
I