[PYTHON] Strengthen with code test ⑤

Introduction

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.

result

Score: 100

Characteristics of the problem

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

Reflections

The choice of what to use for the task of saving the value and processing based on it was shallow.

code

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

Strengthen with code test ⑦
Strengthen with code test ⑨
Strengthen with code test ③
Strengthen with code test ⑤
Strengthen with code test ④
Strengthen with code test ②
Strengthen with code test ①
Strengthen with code test ⑧
Strengthen with code test ⑨
Primality test with Python
Primality test with python
[Memo] Test code summary
Hamming code with numpy
In-house test code culture starting with just one person
Get country code with python
Test embedded software with Google Test
Unit test flask with pytest
Test standard output with Pytest
PyCharm test code automatic generation
Test code for evaluating decorators
Debug Python with VS Code
Load test Websocket with Locust
Check the code with flake8
Document Python code with Doxygen
Test Driven Development with Django Part 4
Test Driven Development with Django Part 6
Classify "Wine" with TensorFlow MLP code
Test Driven Development with Django Part 2
test
Unit test log output with python
Write selenium test code in python
Try running Jupyter with VS Code
It was with Nintendo's Code Puzzle
Test Driven Development with Django Part 1
Install python with mac vs code
Test Driven Development with Django Part 5
Controlling test reruns with Luigi + pytest
Python code to train and test with Custom Vision of Cognitive Service
[Python] Super easy test with assert statement
Stress Test with Locust written in Python
Test Python non-functional programs with GitLab CI
Image classification with Keras-From preprocessing to classification test-
WebUI test with Python2.6 + Selenium 2.44.0 --profile setting
Isn't it okay to write test code?
Generate Japanese test data with Python faker
Test Driven Development Startup with PySide & Pytest
Post Test 3 (Working with PosgreSQL in Python)
Create documentation and test code using doctest.testfile ()
Pass PYTHONPATH in 1 minute with VS Code
Display Japanese graphs with VS Code + matplotlib
How to do portmanteau test with python
Integrating with setuptools / python setup.py test / pytest-runner
Test automation starting with L-Chika (3) Oscilloscope integration
VS Code Pylint is annoying with import! !! !! !!
Automate Facebook App Testing with Facebook Test Users
python setup.py test the code using multiprocess