-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLongDistance.java
More file actions
41 lines (32 loc) · 1.48 KB
/
LongDistance.java
File metadata and controls
41 lines (32 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package com.contest.techgig.y2024;
import java.util.Scanner;
public class LongDistance {
public static void main(String[] args) throws Exception {
Scanner s = new Scanner(System.in);
String firstLine = s.nextLine();
int noOfTestCase = Integer.parseInt(firstLine);
for (int i = 0; i < noOfTestCase; i++) {
String paulInput = s.nextLine();
String ninaInput = s.nextLine();
String[] paulValues = paulInput.split(" ");
String[] ninaValues = ninaInput.split(" ");
int hourTakenByPaul = calculateTimeTakenInHour(Integer.parseInt(paulValues[0]), Integer.parseInt(paulValues[1]),
Integer.parseInt(paulValues[2]));
int hourTakenByNina = calculateTimeTakenInHour(Integer.parseInt(ninaValues[0]), Integer.parseInt(ninaValues[1]),
Integer.parseInt(ninaValues[2]));
if (hourTakenByPaul < hourTakenByNina) {
System.out.println("PAUL");
System.out.println(hourTakenByPaul);
} else if (hourTakenByNina < hourTakenByPaul) {
System.out.println("NINA");
System.out.println(hourTakenByNina);
} else {
System.out.println("BOTH");
System.out.println(hourTakenByPaul);
}
}
}
public static int calculateTimeTakenInHour(int distance, int speed, int noOfRepair) {
return (distance / speed) + noOfRepair;
}
}