336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.
[Python] List 정렬 프로그램 구현
List 에 append 로 integer 값을 하나씩 넣은 후
오름차순 정렬하여 출력하는 프로그램
import sys numberList =[] for j in range(10): i = int(input("input: ")) numberList.append(i) s1= 0 print("Ori: {0}".format(numberList)) while s1 < j: if numberList[s1] > numberList[s1+1]: numberList[s1] ^= numberList[s1+1] numberList[s1+1] ^= numberList[s1] numberList[s1] ^= numberList[s1+1] s1 = s1 + 1 while s1 > 0: if numberList[s1] < numberList[s1-1]: numberList[s1] ^= numberList[s1-1] numberList[s1-1] ^= numberList[s1] numberList[s1] ^= numberList[s1-1] s1 = s1 - 1 print("Sorted: {0}".format(numberList)) print(numberList)
import sys numberList =[] indexList =[] for j in range(10): i = int(input("input: ")) numberList.append(i) indexList.append(0) for k in range(len(numberList)-1): if i < numberList[k]: indexList[k] = indexList[k] + 1 else: indexList[j] = indexList[j] + 1 print("Ori: {0}".format(numberList)) print("Sorted: {0}".format(indexList)) for k1 in range(len(numberList)): for k2 in range(len(numberList)): if k1 == indexList[k2]: sys.stdout.write(str(numberList[k2])) sys.stdout.write(" ") break sys.stdout.write("\n") print(numberList)
'Programming > Python' 카테고리의 다른 글
[Python/OpenCV] Near-Duplicate Image Detection #2 (0) | 2020.06.02 |
---|---|
[Python/OpenCV] Near-Duplicate Image Detection #1 (0) | 2020.06.02 |
[Python 3.6] * 찍기 (0) | 2017.02.02 |