본문 바로가기

Algorithm/Implementation

(C++) - 백준(BOJ) 13496 : The Merchant of Venice

반응형

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

 

13496번: The Merchant of Venice

“The Merchant of Venice” has perhaps one of the most interesting “villains” in Shylock, a Jewish moneylender who has been hurt many times and in different ways by Christians in general, and Antonio, the titular merchant, in particular. When Anton

www.acmicpc.net

간단 구현 문제였습니다.

📕 풀이방법

📔 입력 및 초기화

test case n, 배 하루당 이동거리 s, 상환일 d, 정답을 출력할 and를 선언 후 입력받습니다. 이 후 지역변수 a, b를 선언해 각 배의 정보를 입력받습니다.

📔 풀이과정

s * d가 배가 최대로 이동할 수 있는 거리입니다. 이 값이 a이상이라면 b만큼의 가치를 얻을 수 있으므로 ans에 더해줍니다.

📔 정답출력

형식에 맞게 출력합니다.


📕 Code

#include <bits/stdc++.h>
using namespace std;
int n, s, d, t, ans;
int main(){
  cin >> t;
  for(int i = 1; i <= t; i++){
    cin >> n >> s >> d;
    ans = 0;
    for(int j = 0, a, b; j < n; j++){
      cin >> a >> b;
      if(s * d >= a) ans += b;
    }
    cout << "Data Set " << i <<":\n" << ans << '\n' << '\n';
  }
}

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