-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTom and jerry problem techgig website
72 lines (60 loc) · 1.96 KB
/
Tom and jerry problem techgig website
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
Tom and Jerry (100 Marks)
Tom and Jerry have become enemies because of some misunderstanding and are interfering in each other's work.
Tom has been assigned a construction project of N units which is important for the firm. Jerry got to know about it and took an oath to make it hard for Tom to complete the project.
Tom can do C units of work in daytime so Jerry decided to destroy D units of work in the night time.
Mr. Fred got this information and needs someone to figure out the number of days Tom will take to complete the project of N units with the given scenario.
Can you do it for Mr. Fred?
Note: Tom will always be able to complete the project.
Input Format
The first line of input consists of numbers of test cases, T
Next T lines each consists of three space-separated integers C, D and N.
Constraints
1<= T <=100
1<= N <=10000000
1<= D < C <=N
Output Format
For each test case, print the number of days Tom will take to complete the project in a separate line.
Sample TestCase 1
Input
2
6 2 10
4 3 10
Output
2
7
/* Read input from STDIN. Print your output to STDOUT*/
import java.io.*;
import java.util.*;
import java.lang.Math;
public class CandidateCode {
public static void main(String args[] ) throws Exception {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int t=Integer.parseInt(br.readLine());
while(t>0)
{
String s;
s=br.readLine();
String[] splitStr = s.split("\\s+");
int c=Integer.parseInt(splitStr[0]);
int d=Integer.parseInt(splitStr[1]);
int n=Integer.parseInt(splitStr[2]);
int req=0;
int count=0;
while(req<n)
{
req=req+c;
if(req>=n){
count=count+1;
break;
}
else
{
req=Math.abs(req-d);
}
count=count+1;
}
System.out.println(count);
t=t-1;
}
}
}