반응형
Notice
Recent Posts
Recent Comments
Link
«   2024/07   »
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 31
Archives
Today
Total
07-06 07:47
관리 메뉴

ImJay

[파이썬/Python] 백준 23235번 The Fastest Sorting Algorithm In The World 본문

Solved.ac - Python/Bronze V

[파이썬/Python] 백준 23235번 The Fastest Sorting Algorithm In The World

ImJay 2022. 11. 29. 11:46
반응형

[파이썬/Python] 백준 23235번 The Fastest Sorting Algorithm In The World

 

23235번: The Fastest Sorting Algorithm In The World

It is common to compare sorting algorithms based on their asymptotic speeds. Some slower algorithms like selection sort take O(N2) time to sort N items, while comparison-based sorts like merge sort can go no faster than O(N log(N)) time, under reasonable a

www.acmicpc.net


문제

It is common to compare sorting algorithms based on their asymptotic speeds. Some slower algorithms like selection sort take O(N2) time to sort N items, while comparison-based sorts like merge sort can go no faster than O(N log(N)) time, under reasonable assumptions. Bucket sort, which is not a comparison-based sort, can sort in O(N) time. This is because bucket sort assumes that the range of possible values is small relative to N. In general, the speed of a sorting algorithm depends on the assumptions it can make about the data it is sorting.

One sorting algorithm that is often overlooked, despite its speed, is The Fastest Sorting Algorithm In The World. It sorts in O(1), or constant, time. Of course, the algorithm assumes that the input is an array that is already in fast-access memory and that the input is already sorted. For this problem, implement The Fastest Sorting Algorithm In The World.

 

해설

 

The input file contains multiple test cases. The last test case is followed by a line containing a single zero.

여러 개의 테스트 케이스를 입력 받는다. "0"을 통해 마지막을 구분한다.

 

For each test case, print the case number (beginning with 1) followed by the text Sorting... done!

각 테스트 케이스마다 Case number(1로 시작)와 문자열을 함께 출력한다.

 

코드

case_num = 1

while True:
    case = input()
    if case == "0": break
    print(f"Case {case_num}: Sorting... done!")
    case_num += 1

풀이

1. case number 를 1로 초기화한다.

case_num = 1

 

2. case 를 입력 받고, case가 문자열 0과 일치하면 반복문을 멈춘다

"0"이 아닐 경우, case number 와 함께 문자열을 출력한다.

마지막에 case number를 증가시켜준다.

while True:
    case = input()
    if case == "0": break
    print(f"Case {case_num}: Sorting... done!")
    case_num += 1

 

반응형
Comments