Commit 95038bc6 by BellCodeEditor

auto save

parent 0a7b0048
Showing with 57 additions and 0 deletions
#自己输入n个整数,然后进行从大到小排序
list = []
#input输入的是字符串类型
n = int(input('输入排序元素的个数:'))
for i in range(n):
list.append(int(input('输入一个整数,按回车继续:')))
print('排序前的列表:',list)
#time模块
#time.time()
#返回一个时间戳,秒数
import time
start_time = time.time()
for a in range(0,1001):
for b in range(0,1001):
c = 1000 - a - b
if a**2 + b**2 == c**2:
print('a,b,c三个数分别为',a,b,c)
end_time = time.time()
result = end_time - start_time
print('计算总消耗时间为:',result)
\ No newline at end of file
#冒泡排序:从小到大,从大到小
#重复比较两个相邻元素
#排序n-1轮
alist = [88, 75, 72, 82, 90, 85, 78, 91] alist = [88, 75, 72, 82, 90, 85, 78, 91]
n = len(alist)
for i in range(0,n-1): #排序n-1轮
for j in range(0,n-1): #遍历列表元素下标
if alist[j] > alist[j+1]:
alist[j],alist[j+1] = alist[j+1],alist[j]
print(alist)
import time
start_time = time.time()
list1 = []
for a in range(0, 1000):
for b in range(0, 1000):
list1.append(0)
end_time = time.time()
result = end_time - start_time
print('计算总消耗时间为:',result)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment