IT/알고리즘

백준 8단계(2869)

토니당 2019. 12. 15. 01:55
728x90
반응형
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
 
public class Main {
 
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
    
        String str = br.readLine();
        StringTokenizer st = new StringTokenizer(str);
        
        //올라가는 변수
        long climb = Long.parseLong(st.nextToken());
        //흘러 내려가는 변수
        long fall = Long.parseLong(st.nextToken());
        //목표
        long destination = Long.parseLong(st.nextToken());
        //날
        //만약 (destination - fall) % (climb - fall)이 0이 아니면 나머지가 있다는 뜻으로 하루가 더 걸릴것이고
        //만약 0이면 남은 거리가 없다는 뜻으로 바로 나눈 값 출력하면된다 
        long day = ((destination - fall) % (climb - fall) == 0)? 
                (destination - fall) / (climb - fall) : (destination - fall) / (climb - fall) + 1 ;
        
        bw.write(String.valueOf(day));
        bw.flush();
    }
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 
반응형