vendredi 1 février 2019

Codeforces 1108A wrong output.. what did I do wrong?

Codeforces 1108A - Two distinct points

Hi, I'm practicing Java for fun. I coded as much as I could but cannot figure out what's going on here. When I get 1 query and 4 inputs, it prints two outputs within range but when query is more than 2 my code ignores the range of numbers. How can I solve this problem?

import java.util.Scanner;
import java.util.Random;

public class twoPointDistincts {
  private static int l1,r1,l2,r2,a1,b1 = 0;

  public static void main(String [] args) {
    Scanner scan = new Scanner(System.in);
    int numofQueries = scan.nextInt();

    for(int i = 0; i < numofQueries; i++)
    {
      l1 = scan.nextInt();
      r1 = scan.nextInt();
      l2 = scan.nextInt();
      r2 = scan.nextInt();
    }

    Random ran = new Random();    
    for(int i = 0; i < numofQueries; i++) 
    {
      a1 = ran.nextInt((r1 + 1) - l1) + l1;
      b1 = ran.nextInt((r2 + 1) - l2) + l2; 
      System.out.print (a1 + " ");
      System.out.println(b1);      
    }


  }
}

Input:

5
1 2 1 2
2 6 3 4
2 4 1 3
1 2 1 3
1 4 5 8

Here's the printed value, which is wrong:

3 8
2 7
4 7
4 6
1 5




Aucun commentaire:

Enregistrer un commentaire