※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※

 

이번에 볼 문제는 백준 3733번 문제인 Shares이다.
문제는 아래 링크를 확인하자.

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

 

3733번: Shares

A group of N persons and the ACM Chief Judge share equally a number of S shares (not necessary all of them). Let x be the number of shares aquired by each person (x must be an integer). The problem is to compute the maximum value of x. Write a program that

www.acmicpc.net

N명의 사람과 ACM Chief, 즉 총 N+1명이 S개의 shares를 같은 개수씩(남겨도 된다) 나누어 가져가므로 문제의 해답은 S를 N+1로 나눈 몫이 된다.

 

cin은 입력을 읽는 데에 성공하면 true를, 실패하면 false를 반환하므로 cin과 while문을 이용해 편리하게 구현해보자.

 

아래는 제출한 소스코드이다:

#include <iostream>
using namespace std;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

	int N, S;
	while (cin >> N >> S) cout << S / (N + 1) << '\n';
}
728x90

'BOJ' 카테고리의 다른 글

[BOJ 13496 // C++] The Merchant of Venice  (0) 2022.10.30
[BOJ 10312 // C++] Lodê  (0) 2022.10.30
[BOJ 25881 // C++] Electric Bill  (0) 2022.10.30
[BOJ 25801 // C++] Odd/Even Strings  (0) 2022.10.30
[BOJ 25858 // C++] Divide the Cash  (0) 2022.10.30

+ Recent posts