Advertisement
DakshJain

Untitled

Aug 7th, 2023
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. import java.io.*;
  2. import java.math.*;
  3. import java.security.*;
  4. import java.text.*;
  5. import java.util.*;
  6. import java.util.concurrent.*;
  7. import java.util.function.*;
  8. import java.util.regex.*;
  9. import java.util.stream.*;
  10. import static java.util.stream.Collectors.joining;
  11. import static java.util.stream.Collectors.toList;
  12.  
  13. class Result {
  14.  
  15. /*
  16. * Complete the 'kangaroo' function below.
  17. *
  18. * The function is expected to return a STRING.
  19. * The function accepts following parameters:
  20. * 1. INTEGER x1
  21. * 2. INTEGER v1
  22. * 3. INTEGER x2
  23. * 4. INTEGER v2
  24. */
  25.  
  26. public static String kangaroo(int x1, int v1, int x2, int v2) {
  27. // Write your code here
  28. int out=0;
  29. float div = 0.0f;
  30. float a = (x1 - x2);
  31. float b = (v2 - v1);
  32. // out = a%b ;
  33. div = a/b;
  34. if(div >=0 && Float.compare(div, (float)Math.ceil(div)) == 0){
  35. return "YES";
  36. }else{
  37. return "NO";
  38. }
  39.  
  40.  
  41. }
  42.  
  43. }
  44.  
  45. public class Solution {
  46. public static void main(String[] args) throws IOException {
  47. BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
  48. BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH")));
  49.  
  50. String[] firstMultipleInput = bufferedReader.readLine().replaceAll("\\s+$", "").split(" ");
  51.  
  52. int x1 = Integer.parseInt(firstMultipleInput[0]);
  53.  
  54. int v1 = Integer.parseInt(firstMultipleInput[1]);
  55.  
  56. int x2 = Integer.parseInt(firstMultipleInput[2]);
  57.  
  58. int v2 = Integer.parseInt(firstMultipleInput[3]);
  59.  
  60. String result = Result.kangaroo(x1, v1, x2, v2);
  61.  
  62. bufferedWriter.write(result);
  63. bufferedWriter.newLine();
  64.  
  65. bufferedReader.close();
  66. bufferedWriter.close();
  67. }
  68. }
  69.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement