目录
4,求 a+aa+aaa+.......+aaaaaaaaa=?其中a为1至9之中的一个数,项数也要可以指定。
6,给定一个非负整数数组A,将该数组中的所有偶数都放在奇数元素之前
7,给定一个非负整数数组A,该数组的元素都是从1~N的元素组成,现在发现其中缺失一个,请找出这个缺失的元素
8,小明有一堆苹果,他每天吃掉这堆的一半加一个,等第六天,小明剩余1个苹果,问,这堆苹果共多少个?
一队刚刚出生的兔子,四个月之后,会成为成年兔子,成年兔子每月会生一对小兔子等N个月时,共有多少对兔子
- def busituzi(n : int) -> int:
- if n <= 4:
- return 1
- return busituzi(n-1) + busituzi(n-4)
- print(busituzi(20))
- a = input("请输入一个字符串")
-
- if a[0:] == a[::-1]:
- print("yes")
- else:
- print("no")
- def sushu(n:int) -> int:
- if n == 1:
- return 0
- for i in range(2,n // 2 + 1):
- if n % i == 0:
- return 0
- return 1
-
- n = int(input("请输入N:"))
- sum = 0
- for i in range(n + 1):
- if sushu(i):
- sum += i
- print(sum)
- def ahe(a:int,b:int) -> int:
- temp = ''
- he = 0
- for i in range(b):
- temp = temp + '1'
- he += a * int(temp)
- return he
-
- a = int(input("请输入a的值:"))
- b = int(input("请输入要循环的项数:"))
-
- print(f"所得和为:{ahe(a,b)}")
- def hebing(a:list,b:list) -> list:
- for i in b:
- a.append(i)
- for j in range(len(a) - 1):
- for k in range(len(a) - 1 - j):
- if a[k] > a[k + 1]:
- a[k], a[k + 1] = a[k + 1], a[k]
- return(a)
-
- a=[1,2,3,4]
- b=[2,3,4,5]
-
- print(f"{a},{b}合并后的有序数列为{hebing(a,b)}")
- def oqian(a:list) -> list:
- for i in range(len(a) - 1):
- for j in range(len(a) - 1 - i):
- if a[j + 1] & 1 == 0 and a[j] & 1 == 1:
- a[j], a[j + 1] = a[j + 1], a[j]
- return a
-
- a=[1,2,3,4,5,6]
- print(f"排序后的数列a = {oqian(a)}")
- def zhao(a:list,n:int) -> list:
- b = []
- for j in range(1,n + 1):
- if a.count(j) == 0:
- b.append(j)
-
- return b
-
- a = [1,2,3,4,6,7,8]
- print(f"数组a = {a}")
- print(f"缺失的元素 = {zhao(a,9)}")
- def apple(n : int) -> int:
- if n == 1:
- return 1
- return 2*apple(n-1) + 2
- print(apple(6))