[백준/파이썬/AI] 3733번 Shares 풀이 - ChatGPT 오답과 정답 정리
업데이트:
빠르게 보기
- 핵심은
N명이 아니라N + 1명이 주식을 나눈다는 점입니다. - EOF까지 여러 줄 입력을 받아야 하므로
sys.stdin.readlines()처럼 끝까지 읽는 형태가 편합니다.
문제 정보
- 문제 출처: 백준 온라인 저지
- 문제 링크: 3733번 Shares
- 문제풀이 코드 GitHub 링크
- 제출 언어: PyPy 3
풀이
라이선스
해당 풀이는 ChatGPT를 사용한 것으로, 전적으로 ChatGPT의 GNU GPL v2.0 라이선스를 따릅니다
문제
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 reads pairs of integer numbers from an input text file. Each pair contains the values of 1 ≤ N ≤ 10000 and 1 ≤ S ≤ 109 in that order. The input data are separated freely by white spaces, are correct, and terminate with an end of file. For each pair of numbers the program computes the maximum value of x and prints that value on the standard output from the beginning of a line, as shown in the example below.
대충 번역
n, s를 받아서, n+1명이 s를 균등하게 나눈 몫이 x일때, 자연수x의 최대값을 구하라 EOF까지 계속 입력받아서 출력하라
ChatGPT
Q.
다음 알고리즘 문제를 Python3 언어로 풀어줘
문제 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 reads pairs of integer numbers from an input text file. Each pair contains the values of 1 ≤ N ≤ 10000 and 1 ≤ S ≤ 109 in that order. The input data are separated freely by white spaces, are correct, and terminate with an end of file. For each pair of numbers the program computes the maximum value of x and prints that value on the standard output from the beginning of a line, as shown in the example below.
예제 입력 1 100 2 7 10 9 10 10
예제 출력 50 2 0 0
A.
The problem can be solved by using the following steps:
Read the input data, which contains two integers N and S. Compute the value of x by dividing S by N. Print the value of x on the standard output. Here is an example program in Python3 that implements the above steps:
Copy code
# Read the input data
n, s = map(int, input().split())
# Compute the value of x
x = s // n
# Print the value of x
print(x)
The program first reads the input data, which contains two integers N and S, separated by a space. It then uses the // operator to compute the integer division of S by N, which is the maximum value of x. Finally, the program prints the value of x on the standard output.
Here is an example of how the program works:
Copy code
$ python3 solution.py
1 100
50
$ python3 solution.py
2 7
2
$ python3 solution.py
10 9
0
$ python3 solution.py
10 10
0
The first input 1 100 produces the output 50, which is the maximum value of x that can be obtained by dividing 100 by 1. The second input 2 7 produces the output 2, which is the maximum value of x that can be obtained by dividing 7 by 2. The third and fourth inputs both produce the output 0, which is the maximum value of x that can be obtained by dividing 9 by 10 or 10 by 10.
코드
# Written by chat gpt (gpt3)
## Read the input data
#n, s = map(int, input().split())
#
## Compute the value of x
#x = s // n
#
## Print the value of x
#print(x)
# Improved by neomind
import sys
for line in sys.stdin.readlines():
n, s = map(int, line.split())
# Compute the value of x
x = s // (n+1)
# Print the value of x
print(x)
설명
간단하게 파이썬으로 정수나눗셈을 하는 문제인데, 요즘 코딩 AI들은 알고리즘 문제도 풀 수 있다고 해서 시범적으로 ChatGPT를 써봤는데 영 못푸네요.
덕분에 오랜만에 간단하게나마 알고리즘 문제풀이도 해보네요 ㅎ
사실 처음에는 문제 번호 낮은순으로 봤을때 제가 안 푼 젤 첫 문제인 1005 ACM Craft 부터 풀게 시켰으나,
An error occurred. If this issue persists please contact us through our help center at help.openai.com.
이런 에러를 뱉고 끝나더라구요
문제 입력을 좀 더 간단히 해줘야할 지 고민해봐야겠습니다
이 문제는 계산 자체보다도 문제 문장을 끝까지 읽는 게 더 중요합니다. N persons and the ACM Chief Judge라는 문장 때문에 실제로는 n + 1로 나눠야 정답이 됩니다.
핵심 요약
- 3733번은 정수 나눗셈 자체는 쉽지만, 문제 문장을 제대로 읽지 않으면 쉽게 틀리는 문제입니다.
- AI가 제안한 초안도
n으로 나눠 틀렸기 때문에, 조건을 직접 다시 확인하는 습관이 중요합니다.
이 글과 함께 보면 좋은 글
사칙연산과 구현 문제를 이어서 보면, 간단한 문제에서도 어디서 오답이 나는지 감을 잡기 좋습니다.
- 백준 문제풀이 허브 수학/구현 문제를 더 찾을 때
- 15792번 A/B - 2 풀이 나눗셈 구현 문제를 같이 볼 때
- 1000번 A+B 풀이 기본 사칙연산 문제부터 다시 볼 때
댓글남기기