目录
试题A:排列字母
解答:
msg = input()
print("".join(sorted(msg)))
# 答案:AAAEEEEEEHHHIIILLRRRSSTTWWWY
试题B:寻找整数
解答:
# 2 寻找整数(此题原创详解在这http://t.csdn.cn/yUo5J)
# @Author:小废物GGS
import math
num1=[i for i in range(2,50)] #懒人直接自建数组,不想敲
num2=[1,2,1,4,5,4,1,2,9,0,5,10,11,14,9,0,11,18,9,11,11,15,17,9,23,20,25,16,29,27,25,11,17,4,29,22,37,23,9,1,11,11,33,29,15,5,41,46]
#这里余数很重要啊,一定要一个一个对准来敲,要不然GG
a=True #循环条件
i=0
ans=1
arr=[] #这个数组是存储已经除过的数组(2-49之间的)
#这个函数是求一个数组里面的最小公倍数的,和最小公倍数模版差不多的
def gbs(arr):
k=1
for i in arr:
k=k*i//math.gcd(k,i)
return k
while i<48: #一共就是48个数字嘛,下标是0-47哦,到48就可以停止了
if ans%num1[i]==num2[i]: #判断余数是否相等
arr.append(num1[i]) #相等就存进来
i+=1 #下标+1,继续判断
else:
ans+=gbs(arr) #如果余数不等的话,当前的数字+数组的最小公倍数
print(ans)
#print(2022040920220409)
试题C:纸张尺寸
解答:
#原创在这http://t.csdn.cn/HHQ5W
size_x = 1189
size_y = 841
def duce(n,size_x,size_y,target):
if n != target:
if size_x > size_y:
duce(n+1,int(size_x/2),int(size_y),target)
else:
duce(n+1,int(size_x),int(size_y/2),target)
else:
if size_x > size_y:
print(size_x)
print(size_y)
else:
print(size_y)
print(size_x)
msg = input("")[-1]
duce(0,size_x,size_y,int(msg))
试题D:数位排列
解答:
#原创http://t.csdn.cn/HHQ5W
n = int(input(""))
m = int(input(""))
total = 0
num_list = []
for i in range(1,n+1):
sum_number = sum(list(map(int,list(str(i)))))
if len(num_list) != 0:
for index in range(0,len(num_list)):
if sum_number <= sum(list(map(int,list(str(num_list[index]))))) or index == len(num_list)-1:
num_list.insert(index+1,i)
break
else:
num_list.append(i)
print(num_list[m-1])
试题E:蜂巢
没找到解答
试题F:消除游戏
解答:
s = list(input())
pre = s
f = False
for i in range(pow(2, 64)):
flag = [False]*len(s)
for j in range(1, len(s)-1):
if s[j] == s[j-1] and s[j] != s[j+1]:
flag[j] = True
flag[j+1] = True
if s[j] != s[j-1] and s[j] == s[j+1]:
flag[j-1] = True
flag[j] = True
for j in range(len(flag)):
if flag[j]:
s[j] = ''
s = list(''.join(s))
if len(s) == 0:
f = True
break
if pre == s:
break
pre = s
if f:
print('EMPTY')
else:
print(''.join(s))