15,792,339 members
1.00/5 (1 vote)
See more:
The goal is to print the winner's number ex) scond person = 2

input N which is the number of people playing the game, and rolling five dice roll( dice is normall dice 1~6).

conditions:
1) if the dice number all added during the five rolls exceeds 20 that person is game-over
2) the user close to 20 is the winner
3) if there are more than one user with the closeset number to 20, than the person with smaller number when the numbers rolled from the dice are multipled is the winner

ex)
input :
4
5 2 6 5 4
1 3 4 5 6
6 1 2 3 5
3 3 3 4 6
output : 2

-->input : first line input a number ( how many players )
scond line you get inputs of thr first person's five numbers using space : 5 2 6 5 4
thrid line scond person's dice roll numbers : 1 3 4 5 6
and so on...

output : printing the winner's number --> if second person wins, than the output is 2

i finished coding but the onine judge program printed wrong answer :(

What I have tried:

Python
import sys
num_people = int(input())
dice = [list(map(int, input().split())) for _ in range(num_people)]
dice_multipled = []
multiple = 1
dice_min = []
for i in range(num_people):
if sum(dice[i]) <= 20:
else:
for j in range(num_people):
for x in range(5):
multiple *= int(dice[j][x])
dice_multipled.append(multiple)
multiple = 1

for i in list(dice_index):
dice_min.append(dice_multipled[i])

for i in range(len(dice_index)-1):
if dice_min[i] < dice_min[i+1]:
print(dice_index[i]+1)
else:
print(0)
Posted
Updated 12-May-22 23:48pm
v5
Patrice T 13-May-22 3:10am
Pay attention to indentation, it matters with Python.

## Solution 1

Quote:
i tried coding but got stuck

Your code barely scratch the problem.
You need to use some magic, the magic is to solve the problem by hand with a sheet of paper and a pencil.
The magic is that the procedure you devised is basically the algorithm to solve the problem.
Quote:
1) if the dice number all added during the five rolls exceeds 20 that person is game-over

Python
# This line
if sum(dice[i]) < 20:
# must be replaced by
if sum(dice[i]) <= 20:
# because 20 is allowed

- Learn one or more analyze methods, E.W. Djikstra/N. Wirth Stepwize Refinement/top-Down method is a good start.
Structured Programming.pdf[^]
https://en.wikipedia.org/wiki/Top-down_and_bottom-up_design[^]
https://en.wikipedia.org/wiki/Structured_programming[^]
https://en.wikipedia.org/wiki/Edsger_W._Dijkstra[^]
https://www.cs.utexas.edu/users/EWD/ewd03xx/EWD316.PDF[^]
Program Development by Stepwise Refinement[^]

[Update]
Quote:
i finished coding but the onine judge program printed wrong answer

What is the output with the sample input ?
try different inputs and if output is as expected.

v2
MKG “MNK5168” 13-May-22 1:48am
i did try finishing it by:
import sys
num_people = int(input())
dice = [list(map(int, input().split())) for _ in range(num_people)]
dice_multipled = []
multiple = 1
dice_min = []
for i in range(num_people):
if sum(dice[i]) <= 20:
else:
for j in range(num_people):
for x in range(5):
multiple *= int(dice[j][x])
dice_multipled.append(multiple)
multiple = 1

for i in list(dice_index):
dice_min.append(dice_multipled[i])

for i in range(len(dice_index)-1):
if dice_min[i] < dice_min[i+1]:
print(dice_index[i]+1)
else:
print(0)

but the online evluation program printed wrong answer :(
Patrice T 13-May-22 1:50am
Use Improve question to update your question.
So that everyone can pay attention to this information.