본문 바로가기

Algorithm/Implementation

(C++) - 백준(BOJ) 9622 : Cabin Baggage

반응형

https://www.acmicpc.net/problem/9622

 

9622번: Cabin Baggage

The first line contains an integer t (1≤ t ≤ 300) which determines the number of test cases (i.e. cabin baggage to verify). The following t lines contain the measurement of cabin baggage. Each line contains 4 values which are length, width, depth and w

www.acmicpc.net

구현 문제였습니다.

📕 풀이방법

📔 입력 및 초기화

test case t, 길이 정보 l, wi, d, 무게 we, 정답을 출력할 tot을 선언 후 적절히 입력받습니다.

📔 정답출력

각 무게제한을 초과 하지 않으면 1을 출력하며 tot을 더해줍니다.


📕 Code

#include <bits/stdc++.h>
#define LEN_LIMIT 56.0
#define WID_LIMIT 45.0
#define DEP_LIMIT 25.0
#define WEI_LIMIT 7.0
using namespace std;

double l, wi, d, we, t;
int tot;

int main(){
  cin >> t;
  while(t--){
    cin >> l >> wi >> d >> we;
    if(
      (
        (l <= LEN_LIMIT && wi <= WID_LIMIT && d <= DEP_LIMIT) || l + wi + d <= 125.0)
          && we <= WEI_LIMIT
        ){
        cout << 1 << '\n';
        tot++;
    }
    else cout << 0 << '\n';
  }
  cout << tot << '\n';
}

*더 나은 내용을 위한 지적, 조언은 언제나 환영합니다.