강의

멘토링

커뮤니티

Inflearn Community Q&A

ncsam1609's profile image
ncsam1609

asked

Introduction to Python Algorithm Problem Solving (Coding Test Preparation)

3. Card Reversal

이런 풀이도 괜찮나요?

Written on

·

290

0

import sys
sys.stdin = open("input.txt", "rt")


# 카드 역배치
num_list = [x+1 for x in range(20)]
#print(num_list)

for i in range(10):
    gugan = list(map(int, input().split()))
    #print(gugan)
    num_list[gugan[0]-1:gugan[1]] = reversed(num_list[gugan[0]-1:gugan[1]])

for i in num_list:
    print(i, end = ' ')

 

  1. num_list 생성할 때 x+1 을 해서 1부터 20까지 리스트를 만듦

  2. s, e를 gugan이라는 리스트로 받아서, gugan[0](=s) -1 : gugan[1] 까지의 값을 reversed 시킴

python코테 준비 같이 해요!

Answer 1

0

codingcamp님의 프로필 이미지
codingcamp
Instructor

안녕하세요^^

네. 잘 하신 코드입니다.

ncsam1609's profile image
ncsam1609

asked

Ask a question