[백준/파이썬/AI] 3733번 Shares 풀이 with ChatGPT
업데이트:
문제 정보
- 문제 출처: 백준 온라인 저지
- 문제 링크: 3109번 빵집
- 문제풀이 코드 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.
이런 에러를 뱉고 끝나더라구요
문제 입력을 좀 더 간단히 해줘야할 지 고민해봐야겠습니다
댓글남기기