-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUva573.java
More file actions
43 lines (40 loc) · 1.52 KB
/
Uva573.java
File metadata and controls
43 lines (40 loc) · 1.52 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
42
43
import java.util.*;
import java.io.*;
public class Uva573
{
public static void main(String[] args) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pr = new PrintWriter(System.out);
StringBuilder sb = new StringBuilder();
while(br.ready())
{
StringTokenizer st = new StringTokenizer(br.readLine());
double height = Integer.parseInt(st.nextToken());if(height==0)break;
double distanceClimbed = Integer.parseInt(st.nextToken());
int distanceSlid = Integer.parseInt(st.nextToken());
int factor = Integer.parseInt(st.nextToken());
double decreaseFactor = (double) factor / 100 * distanceClimbed ;
boolean status = false ;
int day = 0 ;
double initialHeight = 0 ;
while(initialHeight <= height && initialHeight >= 0)
{
day++ ;
initialHeight += distanceClimbed ;
if(initialHeight>height)
{
status = true ;
break;
}
initialHeight -= distanceSlid ;
if(distanceClimbed>0) distanceClimbed -= decreaseFactor;
if(distanceClimbed<0) distanceClimbed = 0 ;
}
sb.append(status ? "success":"failure").append(" on day ").append(day).append("\n");
}
pr.print(sb.toString());
pr.close();
br.close();
}
}