Lined Notebook

[3431] [Java] 준환이의 운동관리

by HeshAlgo

<준환이의 운동관리>

문제 설명

https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AWE_ZXcqAAMDFAV2&categoryId=AWE_ZXcqAAMDFAV2&categoryType=CODE

 

내 생각

조건문을 잘 사용 하면 금방 풀 수 있는 문제였습니다. 주어진 조건을 읽고 그대로 조건문 코드로 작성해서 금방 해결 할 수 있었습니다.

 

푼 시간

09분 47초

 

작성 코드

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
// 준환이의 운동관리
import java.io.FileInputStream;
import java.util.*;
 
public class Solution {
 
    public static void main(String args[]) throws Exception {
        String path = "sample_input.txt";
        System.setIn(new FileInputStream(path));
        
        Scanner sc = new Scanner(System.in);
        int T;
        T=sc.nextInt();
    
        for(int test_case = 1; test_case <= T; test_case++) {
            int answer = 0;
            int L = sc.nextInt();
            int U = sc.nextInt();
            int X = sc.nextInt();
            
            if (X < L) {
                answer = L-X;
                System.out.println("#" + test_case + " " + answer);
            } else if (X > U) {
                answer = -1;
                System.out.println("#" + test_case + " " + answer);
            } else if (L <= X && X <=U) {
                System.out.println("#" + test_case + " " + answer);
            }
                
        }
        
        
    }
    
}
 

 

실행 결과

블로그의 정보

꾸준히 공부하는 개발 노트

HeshAlgo

활동하기