I did a code test every day and thought I was more fluent in the language. It is written by someone like a beginner. Almost a memorandum scribbled lessons for the next time.
Score: 100
C 7 9 Check if you are in a certain state. Way of thinking
Get the value every time. If the acquired value is in something stored, add it if there is no path Clear if the value is stored and it becomes almost the same as the target state, otherwise it ends at the end of the loop
It was like that.
Looking back Those that can store Python values --List can be duplicated in various ways At first I added the specified value to the list and checked if it was in the same state as the list, but it was useless if the order was not the same. --Dictionary key and value value alone could be used this time --No duplication of set values I wondered if I should use this, but I didn't understand the addition of values. --Something like a list where tuple elements cannot be changed
The choice of what to use for the task of saving the value and processing based on it was shallow.
python
import sys
input_line = input().split()
count, lens = input_line
#print(count, lens)
sets = {}
for i in range(int(lens)):
sets.setdefault(i+1)
#sets = { i+1 for i in range(int(lens))}#Set int type number
#print(sets)
count_card = {}
for i in range(int(count)):#Loop for the number of times you draw.
out_card = input()#The card that came out
#print(out_card)
if int(out_card) not in count_card:
count_card.setdefault(int(out_card))
#print("Added", count_card)
if count_card == sets:
print(i+1)
sys.exit()
elif i+1 == int(count):
print("unlucky")
elif i+1 == int(count):
print("unlucky")
Recommended Posts