Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 |
Tags
- Serialization
- 혼자 공부하는 C언어
- Graph
- buffer
- R
- s
- insertion sort
- 이것이 자바다
- Selection Sorting
- C programming
- 알기쉬운 알고리즘
- Stack
- 윤성우 열혈자료구조
- Algorithm
- list 컬렉션
- coding test
- 이스케이프 문자
- JSON
- 윤성우의 열혈 자료구조
- 메모리구조
- datastructure
- C 언어 코딩 도장
- stream
Archives
- Today
- Total
Engineering Note
if문 하나 if_else 문으로 가독성 증가 본문
수정 전
import sys
from collections import deque
input = sys.stdin.readline
testcase = int(input())
for _ in range(testcase):
number_of_docs, target = map(int,input().split())
docs = list(map(int,input().split()))
print_q = deque()
for index, value in enumerate(docs):
print_q.append((index,value))
cnt = 1
while print_q:
front_doc = print_q.popleft()
for cur_doc in print_q:
if cur_doc[1] > front_doc[1]:
print_q.append(front_doc)
break
else:
if front_doc[0] == target:
print(cnt)
break
else:
cnt += 1
수정 후
import sys
from collections import deque
sys.stdin = open("input.txt")
input = sys.stdin.readline
testcase = int(input())
for _ in range(testcase):
number_of_docs, target = map(int,input().split())
docs = list(map(int,input().split()))
print_q = deque()
for index, value in enumerate(docs):
print_q.append((index,value))
cnt = 1
while print_q:
front_doc = print_q.popleft()
for document in print_q:
if front_doc[1] >= document[1]:
continue
else:
print_q.append(front_doc)
break
else:
if front_doc[0] == target:
print(cnt)
break
else:
cnt += 1
'Programming Language > Clean_Code' 카테고리의 다른 글
[Clean Code] 훌륭한 소프트웨어 기법 (0) | 2022.02.15 |
---|---|
[Short Code] 숫자를 바라보는 관점에 따른 알고리즘의 변화 (0) | 2022.01.23 |
[BOJ:2259] 부등호 코드 FROM WHILE TO FOR CLEAN코드 (0) | 2021.10.30 |
Comments